pub trait EdgeTrait { fn target(&self) -> N; } pub trait Graph<'a> { type Node; type Edge: EdgeTrait; type NodesIter: Iterator + 'a; type EdgesIter: Iterator + 'a; fn nodes(&'a self) -> Self::NodesIter; fn out_edges(&'a self, u: &Self::Node) -> Self::EdgesIter; fn in_edges(&'a self, u: &Self::Node) -> Self::EdgesIter; fn out_neighbors(&'a self, u: &Self::Node) -> Box> { Box::new(self.out_edges(u).map(|e| e.target())) //~^ ERROR lifetime may not live long enough } fn in_neighbors(&'a self, u: &Self::Node) -> Box> { Box::new(self.in_edges(u).map(|e| e.target())) //~^ ERROR lifetime may not live long enough } } fn main() {}