Is there a way to make an actix-web
route handler aware of a pre-computed heavy object, that is needed for the computation of result
?
What I intend to do, in the end, is to avoid having to recompute my_big_heavy_object
each time a request comes along, and instead compute it once and for all in main
, there access it from the index
method.
extern crate actix_web;
use actix_web::{server, App, HttpRequest};
fn index(_req: HttpRequest) -> HttpResponse {
// how can I access my_big_heavy_object from here?
let result = do_something_with(my_big_heavy_object);
HttpResponse::Ok()
.content_type("application/json")
.body(result)
}
fn main() {
let my_big_heavy_object = compute_big_heavy_object();
server::new(|| App::new().resource("/", |r| r.f(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run();
}