Skip to main content

EdgeBounds

Trait EdgeBounds 

Source
pub trait EdgeBounds<Ix: IndexType = DefaultIx> {
    // Required methods
    fn max_incoming_edges(&self) -> Ix;
    fn max_outgoing_edges(&self) -> Ix;
}
Expand description

Trait for nodes with simple numeric edge count bounds.

This trait provides a convenient way to define nodes that have maximum incoming and outgoing edge counts. Types implementing this trait and the marker trait SimpleEdgeBounds automatically receive a BoundedNode implementation that checks edge counts without considering properties of the other node.

The bounds returned by this trait don’t need to be compile-time constants, but if you want mutable access to node data (via ImmutableEdgeBounds), the values must never change after the node is created.

For more complex logic (e.g., constraints based on node properties), implement BoundedNode directly instead.

§Examples

use petgraph::graph::DefaultIx;
use bounded_graph::{EdgeBounds, SimpleEdgeBounds};

struct MyNode {
    max_in: usize,
    max_out: usize,
}

impl EdgeBounds for MyNode {
    fn max_incoming_edges(&self) -> DefaultIx {
        self.max_in as DefaultIx
    }

    fn max_outgoing_edges(&self) -> DefaultIx {
        self.max_out as DefaultIx
    }
}

// This marker trait enables the automatic BoundedNode implementation
impl SimpleEdgeBounds for MyNode {}

Required Methods§

Source

fn max_incoming_edges(&self) -> Ix

Returns the maximum number of incoming edges this node can have.

Source

fn max_outgoing_edges(&self) -> Ix

Returns the maximum number of outgoing edges this node can have.

Implementors§

Source§

impl<const MAX_IN: usize, const MAX_OUT: usize, T, Ix: IndexType> EdgeBounds<Ix> for FixedEdgeCount<MAX_IN, MAX_OUT, T>