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§
Trait Implementations§
source§impl<N: Clone, E: Clone> SlotMapGraph<N, E> for Graph<N, E>
impl<N: Clone, E: Clone> SlotMapGraph<N, E> for Graph<N, E>
fn nodes(&self) -> &SlotMap<NodeID, Node<N>>
fn nodes_mut(&mut self) -> &mut SlotMap<NodeID, Node<N>>
fn edges(&self) -> &SlotMap<EdgeID, Edge<E>>
fn edges_mut(&mut self) -> &mut SlotMap<EdgeID, Edge<E>>
fn node(&self, id: NodeID) -> Option<&Node<N>>
fn node_mut(&mut self, id: NodeID) -> Option<&mut Node<N>>
fn edge(&self, id: EdgeID) -> Option<&Edge<E>>
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>where
N: RefUnwindSafe,
E: RefUnwindSafe,
impl<N, E> Send for Graph<N, E>
impl<N, E> Sync for Graph<N, E>
impl<N, E> Unpin for Graph<N, E>
impl<N, E> UnwindSafe for Graph<N, E>where
N: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more