Struct fast_graph::Graph

source ·
pub struct Graph<N: Clone, E: Clone> {
    pub nodes: SlotMap<NodeID, Node<N>>,
    pub edges: SlotMap<EdgeID, Edge<E>>,
}
Expand description

The default Graph struct which implements the SlotMapGraph trait.

§Examples

use fast_graph::{Graph, Node, Edge};
/* We need to have these traits in scope: */
use fast_graph::{SlotMapGraph, GraphWriter};

#[derive(Clone, Debug)]
struct EdgeData(String);
#[derive(Clone, Debug)]
struct NodeData(String);

let mut graph: Graph<NodeData, EdgeData> = Graph::new();

let node1 = graph.add_node(NodeData("Node 1".into())).clone();
let node2 = graph.add_node(NodeData("Node 2".into())).clone();
let edge1 = graph.add_edge(node1.id, node2.id, EdgeData("Edge 1".into())).clone();

assert_eq!(graph.node(node1.id).unwrap().id, node1.id);
assert_eq!(graph.edge(edge1.id).unwrap().id, edge1.id);

graph.remove_node(node1.id).unwrap();

assert_eq!(graph.node(node1.id), None);
assert_eq!(graph.node(node2.id).unwrap().id, node2.id);

println!("{:#?}", graph);

Fields§

§nodes: SlotMap<NodeID, Node<N>>§edges: SlotMap<EdgeID, Edge<E>>

Implementations§

source§

impl<N, E> Graph<N, E>
where N: Clone, E: Clone,

source

pub fn new() -> Graph<N, E>

Trait Implementations§

source§

impl<N: Clone + Clone, E: Clone + Clone> Clone for Graph<N, E>

source§

fn clone(&self) -> Graph<N, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<N: Debug + Clone, E: Debug + Clone> Debug for Graph<N, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<N: Clone, E: Clone> SlotMapGraph<N, E> for Graph<N, E>

source§

fn nodes(&self) -> &SlotMap<NodeID, Node<N>>

source§

fn nodes_mut(&mut self) -> &mut SlotMap<NodeID, Node<N>>

source§

fn edges(&self) -> &SlotMap<EdgeID, Edge<E>>

source§

fn edges_mut(&mut self) -> &mut SlotMap<EdgeID, Edge<E>>

source§

fn node(&self, id: NodeID) -> Option<&Node<N>>

source§

fn node_mut(&mut self, id: NodeID) -> Option<&mut Node<N>>

source§

fn edge(&self, id: EdgeID) -> Option<&Edge<E>>

source§

fn edge_mut(&mut self, id: EdgeID) -> Option<&mut Edge<E>>

Auto Trait Implementations§

§

impl<N, E> Freeze for Graph<N, E>

§

impl<N, E> RefUnwindSafe for Graph<N, E>

§

impl<N, E> Send for Graph<N, E>
where N: Send, E: Send,

§

impl<N, E> Sync for Graph<N, E>
where N: Sync, E: Sync,

§

impl<N, E> Unpin for Graph<N, E>
where N: Unpin, E: Unpin,

§

impl<N, E> UnwindSafe for Graph<N, E>
where N: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, N, E> GraphWriter<N, E> for T
where T: SlotMapGraph<N, E> + ?Sized, N: Clone, E: Clone,

source§

fn remove_node(&mut self, id: NodeID) -> Result<(), GraphError>

source§

fn remove_edge(&mut self, id: EdgeID) -> Result<(), GraphError>

source§

fn add_node(&mut self, data: N) -> &Node<N>

source§

fn add_nodes(&mut self, data: &[N]) -> Vec<NodeID>

source§

fn add_edges(&mut self, data: &[(NodeID, NodeID)]) -> Vec<EdgeID>
where E: Default,

source§

fn add_edge(&mut self, from: NodeID, to: NodeID, data: E) -> &mut Edge<E>

source§

fn remove_nodes(&mut self, ids: &[NodeID]) -> Result<(), GraphError>

source§

fn add_edges_with_data(&mut self, data: &[(NodeID, NodeID, E)]) -> Vec<EdgeID>

source§

fn add_nodes_and_edges( &mut self, data: Vec<(N, Vec<NodeID>)> ) -> (Vec<NodeID>, Vec<EdgeID>)
where E: Default,

source§

fn add_nodes_and_edges_with_data( &mut self, node_data: Vec<(N, Vec<(NodeID, E)>)> ) -> (Vec<NodeID>, Vec<EdgeID>)

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.