There seems to be two ways to implement asynchronous of handing web requests:
Method: "impl Future" ... and return by "future::ok" ...
#[get("/job/{job_id}")]
pub fn get_job(path: web::Path<(i64)>) -> impl Future<Item=HttpResponse, Error=actix_web::Error> {
let job_id = path.into_inner();
let job = jobs::load_job(job_id);
future::ok(HttpResponse::Ok().json(job))
}
Doc: https://github.com/actix/examples/blob/master/error_handling/src/main.rs
Method 2: "Box<dyn" and return by "Box::new"...
pub fn candidate_signup(params: web::Form) -> Box<dyn Future<Item = HttpResponse, Error = actix_web::Error>> {
println!("{} | {}", params.username, params.password);
Box::new(futures::future::<_, actix_web::Error>(HttpResponse::Ok().finish()))
}
Doc: Handlers | Actix
Can anyone tell me what are the differences and which one is better?
(Note: In this topic, I'm not talking about anything else like how the parameters are passed, or the functionality of the methods.)