#[derive(Debug, Clone)]
struct Author<T: Persister + Send + Sync + Clone> {
dao: T,
}
impl<T: Persister + Send + Sync + Clone> Author<T> {
fn new(dao: T) -> Self {
Author { dao: dao }
}
fn handle_sign_up<'r>(&self, request: &'r Request, data: Data) -> Outcome<'r> {
Outcome::Success(Response::new())
}
}
impl<T> Handler for Author<T>
where
T: Persister + Send + Sync + Clone + 'static,
{
fn handle<'r>(&self, request: &'r Request, data: Data) -> Outcome<'r> {
Outcome::Success(Response::new())
}
}
impl<T: Persister + Send + Sync + Clone + 'static> Into<Vec<Route>> for Author<T> {
fn into(self) -> Vec<Route> {
vec![Route::new(rocket::http::Method::Post, "/", self)]
}
}
fn main() {
let dao = Dao::new("mysql://user:password@localhost/test".to_owned()).unwrap();
let author = Author::new(dao);
rocket::ignite().mount("/", author).launch();
}
I want to use methods of Author
(ex. Author::handle_sign_up
) as handler for route, but it not works.I have tried to use clouser like below
impl<T: Persister + Send + Sync + Clone + 'static> Into<Vec<Route>> for Author<T> {
fn into(self) -> Vec<Route> {
let p = |req, data| self.handle_sign_up(req, data);
vec![Route::new(rocket::http::Method::Post, "/", p)]
}
}
, compiler reported an lifetime error
mismatched types expected type
for<'r, 's> Fn<(&'r rocket::Request<'s>, rocket::Data)>
found typeFn<(&rocket::Request<'_>, rocket::Data)>
Is there any way to implement it?