pub trait GraphApi<const NODE_COUNT: usize, const EDGE_COUNT: usize> {
// Required methods
fn get_node_descriptors(&self) -> [NodeDescriptor; NODE_COUNT];
fn get_edge_descriptors(&self) -> [EdgeDescriptor; EDGE_COUNT];
fn get_node_policies(&self) -> [NodePolicy; NODE_COUNT];
fn get_edge_policies(&self) -> [EdgePolicy; EDGE_COUNT];
fn edge_occupancy_for<const E: usize>(
&self,
) -> Result<EdgeOccupancy, GraphError>;
fn write_all_edge_occupancies(
&self,
out: &mut [EdgeOccupancy; EDGE_COUNT],
) -> Result<(), GraphError>;
fn refresh_occupancies_for_node<const I: usize, const IN: usize, const OUT: usize>(
&self,
out: &mut [EdgeOccupancy; EDGE_COUNT],
) -> Result<(), GraphError>;
fn step_node_by_index<C, T>(
&mut self,
index: usize,
clock: &C,
telemetry: &mut T,
) -> Result<StepResult, NodeError>
where EdgePolicy: Copy,
C: PlatformClock + Sized,
T: Telemetry + Sized;
// Provided methods
fn validate_graph(&self) -> Result<(), GraphError> { ... }
fn node_policy_for<const I: usize, const IN: usize, const OUT: usize>(
&self,
) -> NodePolicy
where Self: GraphNodeAccess<I> + GraphNodeTypes<I, IN, OUT>,
<Self as GraphNodeAccess<I>>::Node: Node<IN, OUT, <Self as GraphNodeTypes<I, IN, OUT>>::InP, <Self as GraphNodeTypes<I, IN, OUT>>::OutP> { ... }
}Expand description
Unified runtime-facing graph API.
Exposes the minimal surface shared by all runtimes (P0, P1, P2, P2Concurrent).
The NODE_COUNT and EDGE_COUNT const generics define the compile-time
sizes for node and edge descriptor arrays and occupancy snapshots.
§Occupancy buffer semantics
-
write_all_edge_occupancieswrites current occupancy for every edge into the slot whose index equals that edge’sEdgeIndex.0. It must not depend on pre-existing contents ofout. -
refresh_occupancies_for_nodeis a partial, in-place refresh: it MUST update only entries for edges incident to nodeI(either upstream or downstream) and MUST NOT modify any other slots.
If sampling a particular edge fails, implementations should return
Err(GraphError::OccupancySampleFailed(edge_idx)).
Required Methods§
Sourcefn get_node_descriptors(&self) -> [NodeDescriptor; NODE_COUNT]
fn get_node_descriptors(&self) -> [NodeDescriptor; NODE_COUNT]
Returns the static descriptors for all nodes in the graph.
The returned array length must equal NODE_COUNT and be consistent with
the edge descriptors exposed by get_edge_descriptors.
Sourcefn get_edge_descriptors(&self) -> [EdgeDescriptor; EDGE_COUNT]
fn get_edge_descriptors(&self) -> [EdgeDescriptor; EDGE_COUNT]
Returns the static descriptors for all edges in the graph.
The returned array length must equal EDGE_COUNT and reference only valid
node indices described by get_node_descriptors.
Sourcefn get_node_policies(&self) -> [NodePolicy; NODE_COUNT]
fn get_node_policies(&self) -> [NodePolicy; NODE_COUNT]
Returns the static NodePolicy for every node in the graph.
The returned array length must equal NODE_COUNT, and index i
corresponds to NodeIndex::from(i).
Sourcefn get_edge_policies(&self) -> [EdgePolicy; EDGE_COUNT]
fn get_edge_policies(&self) -> [EdgePolicy; EDGE_COUNT]
Returns the static EdgePolicy for every edge in the graph.
The returned array length must equal EDGE_COUNT, and index e
corresponds to EdgeIndex::from(e).
Sourcefn edge_occupancy_for<const E: usize>(
&self,
) -> Result<EdgeOccupancy, GraphError>
fn edge_occupancy_for<const E: usize>( &self, ) -> Result<EdgeOccupancy, GraphError>
Returns a one-shot occupancy snapshot for edge E.
Useful for lightweight telemetry or scheduling decisions that only need the latest observed queue depth for a specific edge.
§Type Parameters
E— The compile-time edge index in0..EDGE_COUNT.
§Errors
Returns a GraphError if E is out of range or the occupancy cannot
be sampled.
Sourcefn write_all_edge_occupancies(
&self,
out: &mut [EdgeOccupancy; EDGE_COUNT],
) -> Result<(), GraphError>
fn write_all_edge_occupancies( &self, out: &mut [EdgeOccupancy; EDGE_COUNT], ) -> Result<(), GraphError>
Write current occupancy for all edges into out.
Contract:
- Must populate every
out[k]with the current occupancy for the edge whoseEdgeIndex.0 == k. - Must not depend on prior
outcontents. - On per-edge sampling failure, return
Err(GraphError::OccupancySampleFailed(edge_idx)).
Sourcefn refresh_occupancies_for_node<const I: usize, const IN: usize, const OUT: usize>(
&self,
out: &mut [EdgeOccupancy; EDGE_COUNT],
) -> Result<(), GraphError>
fn refresh_occupancies_for_node<const I: usize, const IN: usize, const OUT: usize>( &self, out: &mut [EdgeOccupancy; EDGE_COUNT], ) -> Result<(), GraphError>
Partial refresh: update only entries for edges incident to node I.
Contract:
- MUST update
out[k]iff edgekis upstream or downstream of nodeI. - MUST NOT modify any other
out[k]. - If node
Ihas no incident edges, this is a no-op that returnsOk(()). - On sampling failure for any incident edge, return
Err(GraphError::OccupancySampleFailed(edge_idx)).
Sourcefn step_node_by_index<C, T>(
&mut self,
index: usize,
clock: &C,
telemetry: &mut T,
) -> Result<StepResult, NodeError>
fn step_node_by_index<C, T>( &mut self, index: usize, clock: &C, telemetry: &mut T, ) -> Result<StepResult, NodeError>
Drives a single scheduling step for the node at index.
Runtimes P0/P1 use this to advance nodes generically over an abstract clock and telemetry sink without requiring node-specific types.
§Parameters
index— The dynamic node index to step.clock— A clock-like source used by the node during execution.telemetry— A sink for emitting per-step metrics or traces.
§Returns
A StepResult indicating whether work was performed or the node is idle.
§Errors
Returns a NodeError if the node fails to execute its step.
Provided Methods§
Sourcefn validate_graph(&self) -> Result<(), GraphError>
fn validate_graph(&self) -> Result<(), GraphError>
Validates the graph topology and policies derived from node and edge descriptors.
This checks index bounds, arities, endpoint compatibility, and any static
policy invariants enforced by GraphDescBuf::validate.
§Errors
Returns a GraphError if the descriptors are inconsistent or violate
graph-level constraints.
Sourcefn node_policy_for<const I: usize, const IN: usize, const OUT: usize>(
&self,
) -> NodePolicywhere
Self: GraphNodeAccess<I> + GraphNodeTypes<I, IN, OUT>,
<Self as GraphNodeAccess<I>>::Node: Node<IN, OUT, <Self as GraphNodeTypes<I, IN, OUT>>::InP, <Self as GraphNodeTypes<I, IN, OUT>>::OutP>,
fn node_policy_for<const I: usize, const IN: usize, const OUT: usize>(
&self,
) -> NodePolicywhere
Self: GraphNodeAccess<I> + GraphNodeTypes<I, IN, OUT>,
<Self as GraphNodeAccess<I>>::Node: Node<IN, OUT, <Self as GraphNodeTypes<I, IN, OUT>>::InP, <Self as GraphNodeTypes<I, IN, OUT>>::OutP>,
Returns the static NodePolicy for node I (compile-time index).
This queries the node type directly, without requiring an instance step, and is useful for planning or verifying scheduling constraints.
§Type Parameters
I— The compile-time node index in0..NODE_COUNT.IN— The node’s input arity.OUT— The node’s output arity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.