cargo::util::graph

Struct Graph

Source
pub struct Graph<N: Clone, E: Clone> {
    nodes: OrdMap<N, OrdMap<N, E>>,
}

Fields§

§nodes: OrdMap<N, OrdMap<N, E>>

Implementations§

Source§

impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E>

Source

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

Source

pub fn add(&mut self, node: N)

Source

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

Returns the graph obtained by reversing all edges.

Source

pub fn contains<Q>(&self, k: &Q) -> bool
where N: Borrow<Q>, Q: Ord + Eq + ?Sized,

Source

pub fn edge(&self, from: &N, to: &N) -> Option<&E>

Source

pub fn edges(&self, from: &N) -> impl Iterator<Item = (&N, &E)>

Source

pub fn sort(&self) -> Vec<N>

A topological sort of the Graph

Source

fn sort_inner_visit(&self, node: &N, dst: &mut Vec<N>, marks: &mut BTreeSet<N>)

Source

pub fn iter(&self) -> impl Iterator<Item = &N>

Source

pub fn len(&self) -> usize

Source

pub fn is_path_from_to<'a>(&'a self, from: &'a N, to: &'a N) -> bool

Checks if there is a path from from to to.

Source

pub fn path_to_bottom<'a>(&'a self, pkg: &'a N) -> Vec<(&'a N, Option<&'a E>)>

Resolves one of the paths from the given dependent package down to a leaf.

The path return will be the shortest path, or more accurately one of the paths with the shortest length.

Each element contains a node along with an edge except the first one. The representation would look like:

(Node0,) -> (Node1, Edge01) -> (Node2, Edge12)…

Source

pub fn path_to_top<'a>(&'a self, pkg: &'a N) -> Vec<(&'a N, Option<&'a E>)>

Resolves one of the paths from the given dependent package up to the root.

The path return will be the shortest path, or more accurately one of the paths with the shortest length.

Each element contains a node along with an edge except the first one. The representation would look like:

(Node0,) -> (Node1, Edge01) -> (Node2, Edge12)…

Source§

impl<'s, N: Eq + Ord + Clone + 's, E: Default + Clone + 's> Graph<N, E>

Source

fn path_to<'a, F, I>( &'s self, pkg: &'a N, fn_edge: F, ) -> Vec<(&'a N, Option<&'a E>)>
where I: Iterator<Item = (&'a N, &'a E)>, F: Fn(&'s Self, &'a N) -> I, 'a: 's,

Source§

impl<N: Eq + Ord + Clone, E: Clone> Graph<N, E>

Source

fn print_for_test(&self)

Prints the graph for constructing unit tests.

For purposes of graph traversal algorithms the edge values do not matter, and the only value of the node we care about is the order it gets compared in. This constructs a graph with the same topology but with integer keys and unit edges.

Trait Implementations§

Source§

impl<N: Eq + Ord + Clone, E: 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: Display + Eq + Ord + Clone, E: Clone> Debug for Graph<N, E>

Source§

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

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

impl<N: Eq + Ord + Clone, E: Default + Clone> Default for Graph<N, E>

Source§

fn default() -> Graph<N, E>

Returns the “default value” for a type. Read more
Source§

impl<N: Eq + Ord + Clone, E: Eq + Clone> PartialEq for Graph<N, E>

Source§

fn eq(&self, other: &Graph<N, E>) -> 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<N: Eq + Ord + Clone, E: Eq + Clone> Eq for Graph<N, 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>

§

impl<N, E> !Sync for Graph<N, E>

§

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

§

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

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, dst: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 16 bytes