Skip to main content

Module dag

Module dag 

Source
Expand description

A directed acyclic graph with slot handles.

This is the structure ResourceGraph keeps its resources in. It is a directed graph plus one rule the rest of the design leans on: an edge that would close a cycle is refused, so the nodes can always be visited in dependency order.

§Handles

A NodeId names the slot a node occupies together with the generation that slot was in when the node was inserted. Removing a node frees its slot for a later insertion, and that insertion bumps the slot’s generation, so a handle to a removed node never resolves again: it reports “no such node” rather than naming whatever took the slot. Handles can therefore travel through an API that stores only bits — see NodeId::to_bits — and be resolved back with Dag::get, with a stale handle failing loudly instead of silently rebinding. Deciding liveness is still the caller’s job, not the graph’s: ResHandle carries a strong reference that ResourceGraph collects on, so a node whose handle is still held is never removed in the first place.

§Edges

An edge points from a node to a node that depends on it: a dependency, then the resource built from it. Dag::dependencies therefore walks back along the edges, Dag::for_each_dependent_mut walks forward, and Dag::topological_order puts every node after the nodes it depends on. An edge is recorded once however often it is declared, which Dag::add_edge reports: only the declaration that recorded it returns true.

Re-exports§

use std::vec::Vec; 🔒

Structs§

Dag
A directed acyclic graph whose edges may not close a cycle.
EdgeSlot 🔒
An edge, pointing from a dependency to what depends on it.
NodeId
The slot a node occupies in a Dag, with the generation it was in.
NodeSlot 🔒
A slot a node occupies.

Enums§

EdgeError
Why Dag::add_edge refused an edge.