How to fix: expected concrete lifetime, but found bound lifetime parameter

可紊 提交于 2019-12-02 08:28:19

After making your example a bit more minimal (getting rid of the http dependency), and some suggestions on IRC (namely someone pointing out that the problem goes away if you remove the deriving(Clone) from the Route), you can see a fixed version below (--cfg v2)

#[deriving(Clone)]
pub struct RouteStore{
    pub routes: Vec<Route>,
}

#[cfg(v1)]
#[deriving(Clone)]
struct Route {
    path: String,
    handler: fn(response: &mut ())
}

#[cfg(v2)]
struct Route {
    path: String,
    handler: fn(response: &mut ())
}

#[cfg(v2)]
impl Clone for Route {
    fn clone(&self) -> Route {
        Route { path: self.path.clone(), handler: self.handler }
    }
}
impl RouteStore {
    pub fn new () -> RouteStore {
        RouteStore {
            routes: Vec::new()
        }
    }

    fn add_route (&mut self, path: String, handler: fn(response: &mut ())) -> () {
        let route = Route {
            path: path,
            handler: handler
        };
        self.routes.push(route);
    }
}

fn main () {

}

The issue here is that an fn does not implement Clone. (edit: Well, it does have a clone method, but the returned value does not seem compatible with what that field needs. The v2 version above just side-steps the whole issue.)

So I suspect the error you are seeing is coming from the auto-generated clone implementation that deriving(Clone) injects.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!