pub struct Edge<W = ()> {
pub source: NodeId,
pub target: NodeId,
pub weight: W,
}Expand description
A directed edge from source to target carrying a weight of type W.
For unweighted graphs use W = () (the default). For weighted graphs use
any numeric type, most commonly f64.
§Examples
use graph_core::{Edge, NodeId};
let u = NodeId::new(0);
let v = NodeId::new(1);
// Weighted edge
let weighted = Edge::new(u, v, 3.5_f64);
assert_eq!(weighted.weight, 3.5);
// Unweighted edge (weight = ())
let unweighted: Edge<()> = Edge::new(u, v, ());
assert_eq!(unweighted.source, u);
assert_eq!(unweighted.target, v);Fields§
§source: NodeIdThe node this edge originates from.
target: NodeIdThe node this edge points to.
weight: WThe edge weight. Use () for unweighted graphs.
Implementations§
Source§impl<W> Edge<W>
impl<W> Edge<W>
Sourcepub fn new(source: NodeId, target: NodeId, weight: W) -> Self
pub fn new(source: NodeId, target: NodeId, weight: W) -> Self
Creates a new directed edge.
§Examples
use graph_core::{Edge, NodeId};
let e = Edge::new(NodeId::new(0), NodeId::new(1), 2.0_f64);
assert_eq!(e.weight, 2.0);Sourcepub fn is_self_loop(&self) -> bool
pub fn is_self_loop(&self) -> bool
Returns true if this is a self-loop (source == target).
§Examples
use graph_core::{Edge, NodeId};
let looped = Edge::new(NodeId::new(3), NodeId::new(3), ());
assert!(looped.is_self_loop());
let normal = Edge::new(NodeId::new(0), NodeId::new(1), ());
assert!(!normal.is_self_loop());Sourcepub fn reversed(self) -> Selfwhere
W: Clone,
pub fn reversed(self) -> Selfwhere
W: Clone,
Returns the reversed edge (source and target swapped, weight unchanged).
§Examples
use graph_core::{Edge, NodeId};
let e = Edge::new(NodeId::new(0), NodeId::new(1), 5u32);
let r = e.reversed();
assert_eq!(r.source, NodeId::new(1));
assert_eq!(r.target, NodeId::new(0));
assert_eq!(r.weight, 5);Trait Implementations§
impl<W> StructuralPartialEq for Edge<W>
Auto Trait Implementations§
impl<W> Freeze for Edge<W>where
W: Freeze,
impl<W> RefUnwindSafe for Edge<W>where
W: RefUnwindSafe,
impl<W> Send for Edge<W>where
W: Send,
impl<W> Sync for Edge<W>where
W: Sync,
impl<W> Unpin for Edge<W>where
W: Unpin,
impl<W> UnwindSafe for Edge<W>where
W: 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