Edge

Struct Edge 

Source
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: NodeId

The node this edge originates from.

§target: NodeId

The node this edge points to.

§weight: W

The edge weight. Use () for unweighted graphs.

Implementations§

Source§

impl<W> Edge<W>

Source

pub fn new(source: NodeId, target: NodeId, weight: W) -> Edge<W>

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);
Source

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());
Source

pub fn reversed(self) -> Edge<W>
where 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§

Source§

impl<W> Clone for Edge<W>
where W: Clone,

Source§

fn clone(&self) -> Edge<W>

Returns a duplicate 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<W> Debug for Edge<W>
where W: Debug,

Source§

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

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

impl<W> PartialEq for Edge<W>
where W: PartialEq,

Source§

fn eq(&self, other: &Edge<W>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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>,

Source§

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>,

Source§

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.