pub struct ProcessingGraph {
pub nodes: Vec<GraphNode>,
pub edges: Vec<GraphEdge>,
pub is_locked: bool,
}Expand description
A directed acyclic graph of media processing nodes.
Fields§
§nodes: Vec<GraphNode>All nodes in the graph.
edges: Vec<GraphEdge>All edges in the graph.
is_locked: boolWhen true the graph is considered executing and hot-swap is refused.
Implementations§
Source§impl ProcessingGraph
impl ProcessingGraph
Sourcepub fn add_node(&mut self, node: GraphNode)
pub fn add_node(&mut self, node: GraphNode)
Adds node to the graph. Duplicate IDs are allowed but discouraged.
Sourcepub fn remove_node(&mut self, id: u64) -> bool
pub fn remove_node(&mut self, id: u64) -> bool
Removes the node with id and all edges referencing it.
Returns true if a node was removed.
Sourcepub fn connect(
&mut self,
from: u64,
from_port: u32,
to: u64,
to_port: u32,
) -> bool
pub fn connect( &mut self, from: u64, from_port: u32, to: u64, to_port: u32, ) -> bool
Adds an edge from (from, from_port) to (to, to_port).
Returns false if either node does not exist; true on success.
Sourcepub fn disconnect(&mut self, from: u64, to: u64) -> bool
pub fn disconnect(&mut self, from: u64, to: u64) -> bool
Removes all edges from node from to node to.
Returns true if at least one edge was removed.
Sourcepub fn source_nodes(&self) -> Vec<&GraphNode>
pub fn source_nodes(&self) -> Vec<&GraphNode>
Returns references to all nodes whose type has zero inputs (source nodes).
Sourcepub fn sink_nodes(&self) -> Vec<&GraphNode>
pub fn sink_nodes(&self) -> Vec<&GraphNode>
Returns references to all nodes whose type has zero outputs (sink nodes).
Sourcepub fn execution_order(&self) -> Vec<u64>
pub fn execution_order(&self) -> Vec<u64>
Returns node IDs in topological execution order (Kahn’s algorithm).
Nodes not reachable from any source, or that form cycles, are appended in arbitrary order at the end.
Source§impl ProcessingGraph
impl ProcessingGraph
Sourcepub fn hot_swap_node(
&mut self,
node_id: u64,
replacement: GraphNode,
) -> HotSwapResult
pub fn hot_swap_node( &mut self, node_id: u64, replacement: GraphNode, ) -> HotSwapResult
Replace the node identified by node_id with replacement.
All edges connected to node_id are preserved — only the node’s
internal data (name, params, type) is swapped. The swap is refused if:
node_idis not present in the graph →HotSwapResult::NodeNotFound- the graph is locked (executing) →
HotSwapResult::GraphLocked - the port signatures are incompatible →
HotSwapResult::IncompatiblePorts
When HotSwapResult::Success is returned the replacement node’s id
field is forced to node_id so that all edge references remain valid.
§Complexity
O(n) where n is the number of nodes (linear scan to locate the node slot). Edge preservation is trivially O(1) because edges reference node IDs, not positions; no edge data is modified.
Sourcepub fn lock(&mut self)
pub fn lock(&mut self)
Lock the graph to simulate an executing state (prevents hot-swap).
Call ProcessingGraph::unlock when execution completes.
Trait Implementations§
Source§impl Debug for ProcessingGraph
impl Debug for ProcessingGraph
Source§impl Default for ProcessingGraph
impl Default for ProcessingGraph
Source§fn default() -> ProcessingGraph
fn default() -> ProcessingGraph
Auto Trait Implementations§
impl Freeze for ProcessingGraph
impl RefUnwindSafe for ProcessingGraph
impl Send for ProcessingGraph
impl Sync for ProcessingGraph
impl Unpin for ProcessingGraph
impl UnsafeUnpin for ProcessingGraph
impl UnwindSafe for ProcessingGraph
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> 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 more