Cycles

Trait Cycles 

Source
pub trait Cycles {
    type NodeId;

    // Required methods
    fn visit_cycles<F, B>(&self, visitor: F) -> Option<B>
       where F: FnMut(&Self, &[Self::NodeId]) -> ControlFlow<B>;
    fn cycles(&self) -> Vec<Vec<Self::NodeId>>;

    // Provided method
    fn visit_all_cycles<F>(&self, visitor: F)
       where F: FnMut(&Self, &[Self::NodeId]) { ... }
}
Expand description

Trait for identifying cycles in a graph

Required Associated Types§

Source

type NodeId

The node identifier of the underlying graph

Required Methods§

Source

fn visit_cycles<F, B>(&self, visitor: F) -> Option<B>
where F: FnMut(&Self, &[Self::NodeId]) -> ControlFlow<B>,

Apply the visitor to each cycle until we are told to stop

The first argument passed to the visitor is a reference to the graph and the second one a slice with all nodes that form the cycle. If at any point the visitor returns ControlFlow::Break(b) this function stops visiting any further cycles and returns Some(b). Otherwise the return value is None.

Source

fn cycles(&self) -> Vec<Vec<Self::NodeId>>

Find all cycles

Each element of the returned Vec is a Vec of all nodes in one cycle.

Provided Methods§

Source

fn visit_all_cycles<F>(&self, visitor: F)
where F: FnMut(&Self, &[Self::NodeId]),

Apply the visitor to each cycle until we are told to stop

The first argument passed to the visitor is a reference to the graph and the second one a slice with all nodes that form the cycle.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Graph: GraphBase> Cycles for Graph

Source§

type NodeId = <Graph as GraphBase>::NodeId