Skip to main content

NetworkGraphWrite

Trait NetworkGraphWrite 

pub trait NetworkGraphWrite {
    type Error;
    type Observed: EdgeObservable + Send;
    type NodeId: Send;

    // Required methods
    fn add_node(&self, key: Self::NodeId);
    fn remove_node(&self, key: &Self::NodeId);
    fn add_edge(
        &self,
        src: &Self::NodeId,
        dest: &Self::NodeId,
    ) -> Result<(), Self::Error>;
    fn remove_edge(&self, src: &Self::NodeId, dest: &Self::NodeId);
    fn upsert_edge<F>(&self, src: &Self::NodeId, dest: &Self::NodeId, f: F)
       where F: FnOnce(&mut Self::Observed);
}
Expand description

A trait for mutating the graph topology.

Provides methods to add/remove nodes and add edges.

Required Associated Types§

type Error

The error type returned by fallible write operations.

type Observed: EdgeObservable + Send

The concrete type of observations for peers.

type NodeId: Send

The identifier type used to reference nodes in the graph.

Required Methods§

fn add_node(&self, key: Self::NodeId)

Adds a node to the graph if it does not already exist.

fn remove_node(&self, key: &Self::NodeId)

Removes a node and all its associated edges from the graph.

fn add_edge( &self, src: &Self::NodeId, dest: &Self::NodeId, ) -> Result<(), Self::Error>

Adds a directed edge between two existing nodes with default observations.

Returns an error if either node is not present in the graph.

fn remove_edge(&self, src: &Self::NodeId, dest: &Self::NodeId)

Removes a directed edge between two nodes.

If the edge does not exist, this operation has no effect.

fn upsert_edge<F>(&self, src: &Self::NodeId, dest: &Self::NodeId, f: F)
where F: FnOnce(&mut Self::Observed),

Updates an existing edge or inserts a new edge between two nodes.

If the nodes do not exist, they are inserted into the graph.

The provided closure f is applied to modify the edge’s observations. If the edge already exists, its observations are updated. If the edge does not exist, it is created and the closure is applied.

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.

Implementations on Foreign Types§

§

impl<'a, T> NetworkGraphWrite for &'a T
where T: 'a + NetworkGraphWrite + ?Sized,

§

impl<T> NetworkGraphWrite for Box<T>

§

type Error = <T as NetworkGraphWrite>::Error

§

type Observed = <T as NetworkGraphWrite>::Observed

§

type NodeId = <T as NetworkGraphWrite>::NodeId

§

fn add_node(&self, key: <Box<T> as NetworkGraphWrite>::NodeId)

§

fn remove_node(&self, key: &<Box<T> as NetworkGraphWrite>::NodeId)

§

fn add_edge( &self, src: &<Box<T> as NetworkGraphWrite>::NodeId, dest: &<Box<T> as NetworkGraphWrite>::NodeId, ) -> Result<(), <Box<T> as NetworkGraphWrite>::Error>

§

fn remove_edge( &self, src: &<Box<T> as NetworkGraphWrite>::NodeId, dest: &<Box<T> as NetworkGraphWrite>::NodeId, )

§

fn upsert_edge<F>( &self, src: &<Box<T> as NetworkGraphWrite>::NodeId, dest: &<Box<T> as NetworkGraphWrite>::NodeId, f: F, )
where F: FnOnce(&mut <Box<T> as NetworkGraphWrite>::Observed),

§

impl<T> NetworkGraphWrite for Arc<T>

§

type Error = <T as NetworkGraphWrite>::Error

§

type Observed = <T as NetworkGraphWrite>::Observed

§

type NodeId = <T as NetworkGraphWrite>::NodeId

§

fn add_node(&self, key: <Arc<T> as NetworkGraphWrite>::NodeId)

§

fn remove_node(&self, key: &<Arc<T> as NetworkGraphWrite>::NodeId)

§

fn add_edge( &self, src: &<Arc<T> as NetworkGraphWrite>::NodeId, dest: &<Arc<T> as NetworkGraphWrite>::NodeId, ) -> Result<(), <Arc<T> as NetworkGraphWrite>::Error>

§

fn remove_edge( &self, src: &<Arc<T> as NetworkGraphWrite>::NodeId, dest: &<Arc<T> as NetworkGraphWrite>::NodeId, )

§

fn upsert_edge<F>( &self, src: &<Arc<T> as NetworkGraphWrite>::NodeId, dest: &<Arc<T> as NetworkGraphWrite>::NodeId, f: F, )
where F: FnOnce(&mut <Arc<T> as NetworkGraphWrite>::Observed),

Implementors§