I want to have a context-struct that is available in all handlers, but I am not able to get trough the compiler.
For an example, I want something like this
extern crate iron;
extern crate router;
use iron::prelude::*;
use router::Router;
use std::collections::HashMap;
struct Context {
cache: HashMap<String, String>,
}
fn main() {
let mut context = Context { cache: HashMap::new(), };
let mut router = Router::new();
router.get("/", |request| index(request, context));
Iron::new(router).http("localhost:80").unwrap();
}
fn index(_: &mut Request, context: Context) -> IronResult<Response> {
Ok(Response::with((iron::status::Ok, "index")))
}
This won't compile with a lengthy error message
error: type mismatch resolving `for<'r, 'r, 'r> <[closure@src\main.rs:... context:_] as std::ops::FnOnce<(&'r mut iron::Request<'r, 'r>,)>>::Output == std::result::Result<iron::Response, iron::IronError>`:
expected bound lifetime parameter ,
found concrete lifetime [E0271]
src\main.rs:... router.get("/", |request| index(request, context));