I'm currently pulling my hear out over this one. I tried to shrink it down to a minimal reproducible example.
struct Request;
struct ResponseWriter<'a> {
dummy: &'a ()
}
#[deriving(Clone)]
pub struct RouteStore{
pub routes: Vec<Route>,
}
#[deriving(Clone)]
struct Route {
path: String,
handler: fn(request: &Request, response: &mut ResponseWriter)
}
impl RouteStore {
pub fn new () -> RouteStore {
RouteStore {
routes: Vec::new()
}
}
fn add_route (&mut self, path: String, handler: fn(request: &Request, response: &mut ResponseWriter)) -> () {
let route = Route {
path: path,
handler: handler
};
self.routes.push(route);
}
}
fn main () {
}
This leaves me with:
error: mismatched types: expected `fn(&http::server::request::Request, &mut http::server::response::ResponseWriter<>)` but found `fn(&http::server::request::Request, &mut http::server::response::ResponseWriter<>)` (expected concrete lifetime, but found bound lifetime parameter )
src/so.rs:12 handler: fn(request: &Request, response: &mut ResponseWriter)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Previously I stored my fn
in a HashMap
like this HashMap<String, fn(request: &Request, response: &mut ResponseWriter)>
. This worked fine.
But now I want to refactor things a bit and introduced a Route
struct and store things as Vec<Route>
. But suddenly hell breaks loose and I don't know how to fix it :-/
For the curious ones, this is part of my effort to write an expressjs inspired web framework for Rust called Floor