pub struct DependencyGraph { /* private fields */ }Expand description
Tracks dependency relationships between assets.
Maintains two maps:
dependencies: forward edges (asset -> what it depends on)dependents: reverse edges (asset -> who depends on it)
Supports cycle detection when adding edges and BFS cascade ordering for reload propagation.
§Example
use goud_engine::assets::dependency::DependencyGraph;
let mut graph = DependencyGraph::new();
graph.add_dependency("shader.glsl", "common.glsl").unwrap();
graph.add_dependency("material.json", "shader.glsl").unwrap();
// When common.glsl changes, reload shader.glsl then material.json
let order = graph.get_cascade_order("common.glsl");
assert_eq!(order, vec!["shader.glsl", "material.json"]);Implementations§
Source§impl DependencyGraph
impl DependencyGraph
Sourcepub fn add_dependency(
&mut self,
asset: &str,
depends_on: &str,
) -> Result<(), CycleError>
pub fn add_dependency( &mut self, asset: &str, depends_on: &str, ) -> Result<(), CycleError>
Adds a dependency: asset depends on depends_on.
Returns Err(CycleError) if adding this edge would create a cycle.
§Arguments
asset- The asset that has the dependencydepends_on- The asset being depended upon
Sourcepub fn get_cascade_order(&self, changed_path: &str) -> Vec<String>
pub fn get_cascade_order(&self, changed_path: &str) -> Vec<String>
Returns the cascade reload order for a changed asset.
Performs a BFS over reverse edges (dependents) to produce a topological ordering: assets closer to the changed asset are reloaded first.
The changed asset itself is NOT included in the output.
§Arguments
changed_path- The path of the asset that changed
Sourcepub fn remove_asset(&mut self, path: &str)
pub fn remove_asset(&mut self, path: &str)
Removes an asset and all its edges from the graph.
Cleans up both forward and reverse edges so no dangling references remain.
Sourcepub fn get_dependencies(&self, asset: &str) -> Option<&HashSet<String>>
pub fn get_dependencies(&self, asset: &str) -> Option<&HashSet<String>>
Returns the set of assets that asset directly depends on.
Sourcepub fn get_dependents(&self, asset: &str) -> Option<&HashSet<String>>
pub fn get_dependents(&self, asset: &str) -> Option<&HashSet<String>>
Returns the set of assets that directly depend on asset.
Sourcepub fn contains(&self, asset: &str) -> bool
pub fn contains(&self, asset: &str) -> bool
Returns true if the graph contains any edges for the given asset.
Sourcepub fn asset_count(&self) -> usize
pub fn asset_count(&self) -> usize
Returns the total number of assets tracked in the graph.
Trait Implementations§
Source§impl Debug for DependencyGraph
impl Debug 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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().