File size: 1,380 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/// The control flow of visiting an edge during a graph traversal.
pub enum VisitControlFlow<Node, Abort = !> {
/// The traversal should continue on the outgoing edges of the given node.
Continue(Node),
/// The traversal should skip visiting the edges the given node.
Skip(Node),
/// The traversal should abort and return immediately.
Abort(Abort),
}
impl<Node, Abort> VisitControlFlow<Node, Abort> {
/// Map the continue and skip values of this control flow.
pub fn map_node<Map, Mapped>(self, mut map: Map) -> VisitControlFlow<Mapped, Abort>
where
Map: FnMut(Node) -> Mapped,
{
match self {
VisitControlFlow::Continue(node) => VisitControlFlow::Continue(map(node)),
VisitControlFlow::Skip(node) => VisitControlFlow::Skip(map(node)),
VisitControlFlow::Abort(abort) => VisitControlFlow::Abort(abort),
}
}
/// Map the abort value of this control flow.
pub fn map_abort<Map, Mapped>(self, mut map: Map) -> VisitControlFlow<Node, Mapped>
where
Map: FnMut(Abort) -> Mapped,
{
match self {
VisitControlFlow::Continue(node) => VisitControlFlow::Continue(node),
VisitControlFlow::Skip(node) => VisitControlFlow::Skip(node),
VisitControlFlow::Abort(abort) => VisitControlFlow::Abort(map(abort)),
}
}
}
|