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
impl DependencyGraph
Sourcepub fn builder() -> DependencyGraphBuilder
pub fn builder() -> DependencyGraphBuilder
Create a DependencyGraphBuilder.
This can be useful to construct a populated DependencyGraph in e.g. unit tests.
Sourcepub fn clear_dependencies(&mut self, id: &ResourceId)
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);Sourcepub fn add_dependency(&mut self, id: ResourceId, dependency: ResourceId)
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);Sourcepub fn set_dependencies(
&mut self,
id: ResourceId,
dependencies: impl IntoIterator<Item = ResourceId>,
)
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);Sourcepub fn get(&self, id: &ResourceId) -> Option<DependencyNode<'_>>
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);Sourcepub fn iter(&self) -> Iter<'_> ⓘ
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
impl Clone for DependencyGraph
Source§fn clone(&self) -> DependencyGraph
fn clone(&self) -> DependencyGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DependencyGraph
impl Debug for DependencyGraph
Source§impl Default for DependencyGraph
impl Default for DependencyGraph
Source§fn default() -> DependencyGraph
fn default() -> DependencyGraph
impl Eq for DependencyGraph
Source§impl PartialEq for DependencyGraph
impl PartialEq for DependencyGraph
Source§fn eq(&self, other: &DependencyGraph) -> bool
fn eq(&self, other: &DependencyGraph) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for DependencyGraph
Auto Trait Implementations§
impl Freeze for DependencyGraph
impl RefUnwindSafe for DependencyGraph
impl Send for DependencyGraph
impl Sync for DependencyGraph
impl Unpin for DependencyGraph
impl UnsafeUnpin for DependencyGraph
impl UnwindSafe for DependencyGraph
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.