Skip to main content

DependencyGraph

Struct DependencyGraph 

Source
pub struct DependencyGraph { /* private fields */ }
Expand description

A graph of dependency relations between resources.

Dependency relations can be traversed via DependencyNodes. Any resource that has dependencies or dependents can be accessed via DependencyGraph::get().

DependencyGraphs are comparable via equivalence relations.

Implementations§

Source§

impl DependencyGraph

Source

pub fn builder() -> DependencyGraphBuilder

Create a DependencyGraphBuilder.

This can be useful to construct a populated DependencyGraph in e.g. unit tests.

Source

pub fn clear_dependencies(&mut self, id: &ResourceId)

Clear all dependency relations for a particular resource in this graph.

use gtether::resource::id::ResourceId;
use gtether::resource::manager::dependency::DependencyGraph;

let mut graph = DependencyGraph::builder().add("a", ["b", "c"]).add("b", ["c"]).build();
let expected_graph = DependencyGraph::builder().add("b", ["c"]).build();

let id = ResourceId::from("a");
graph.clear_dependencies(&id);
assert_eq!(graph, expected_graph);
assert_eq!(graph.get(&id), None);
Source

pub fn add_dependency(&mut self, id: ResourceId, dependency: ResourceId)

Add a dependency relation for a particular resource in this graph.

use gtether::resource::id::ResourceId;
use gtether::resource::manager::dependency::DependencyGraph;

let mut graph = DependencyGraph::builder().add("a", ["b"]).build();
let expected_graph = DependencyGraph::builder().add("a", ["b", "c"]).build();

graph.add_dependency(ResourceId::from("a"), ResourceId::from("c"));
assert_eq!(graph, expected_graph);
Source

pub fn set_dependencies( &mut self, id: ResourceId, dependencies: impl IntoIterator<Item = ResourceId>, )

Set the dependency relations for a particular resource in this graph.

use gtether::resource::id::ResourceId;
use gtether::resource::manager::dependency::DependencyGraph;

let mut graph = DependencyGraph::builder().add("a", ["b", "c"]).build();
let expected_graph = DependencyGraph::builder().add("a", ["d", "e"]).build();

graph.set_dependencies(ResourceId::from("a"), [ResourceId::from("d"), ResourceId::from("e")]);
assert_eq!(graph, expected_graph);
Source

pub fn get(&self, id: &ResourceId) -> Option<DependencyNode<'_>>

Get a DependencyNode for a particular resource in this graph.

If the given resource does not have any dependencies or dependents, it will not be in the graph, and so this method will return None.

use gtether::resource::id::ResourceId;
use gtether::resource::manager::dependency::DependencyGraph;

let graph = DependencyGraph::builder().add("a", ["b"]).build();

let id_a = ResourceId::from("a");
let id_b = ResourceId::from("b");
let id_c = ResourceId::from("c");

assert_eq!(graph.get(&id_a).unwrap().id(), &id_a);
assert_eq!(graph.get(&id_b).unwrap().id(), &id_b);
assert_eq!(graph.get(&id_c), None);
Source

pub fn iter(&self) -> Iter<'_>

Iterate over all dependencies in this graph, in no particular order.

This will only iterate over nodes that have dependencies, and will not iterate over leaf nodes.

use std::collections::HashSet;
use gtether::resource::id::ResourceId;
use gtether::resource::manager::dependency::DependencyGraph;

let graph = DependencyGraph::builder().add("a", ["b", "c"]).add("b", ["c"]).build();
let expected_ids = ["a", "b"].into_iter()
    .map(ResourceId::from)
    .collect::<HashSet<_>>();

let ids = graph.iter()
    .map(|node| node.id().clone())
    .collect::<HashSet<_>>();
assert_eq!(ids, expected_ids);

Trait Implementations§

Source§

impl Clone for DependencyGraph

Source§

fn clone(&self) -> DependencyGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DependencyGraph

Source§

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

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

impl Default for DependencyGraph

Source§

fn default() -> DependencyGraph

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

impl Eq for DependencyGraph

Source§

impl PartialEq for DependencyGraph

Source§

fn eq(&self, other: &DependencyGraph) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for DependencyGraph

Auto Trait Implementations§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

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

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

Source§

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.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

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> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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