2018-11-08 17:18:55 -06:00
|
|
|
pub trait EdgeTrait<N> {
|
|
|
|
fn target(&self) -> N;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Graph<'a> {
|
|
|
|
type Node;
|
|
|
|
type Edge: EdgeTrait<Self::Node>;
|
|
|
|
type NodesIter: Iterator<Item = Self::Node> + 'a;
|
|
|
|
type EdgesIter: Iterator<Item = Self::Edge> + '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;
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn out_neighbors(&'a self, u: &Self::Node) -> Box<dyn Iterator<Item = Self::Node>> {
|
2018-11-08 17:18:55 -06:00
|
|
|
Box::new(self.out_edges(u).map(|e| e.target()))
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2018-11-08 17:18:55 -06:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:46:13 -05:00
|
|
|
fn in_neighbors(&'a self, u: &Self::Node) -> Box<dyn Iterator<Item = Self::Node>> {
|
2018-11-08 17:18:55 -06:00
|
|
|
Box::new(self.in_edges(u).map(|e| e.target()))
|
2022-04-01 12:13:25 -05:00
|
|
|
//~^ ERROR lifetime may not live long enough
|
2018-11-08 17:18:55 -06:00
|
|
|
}
|
|
|
|
}
|
2018-12-16 11:23:27 -06:00
|
|
|
|
|
|
|
fn main() {}
|