Skip to main content

GraphApi

Trait GraphApi 

Source
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_occupancies writes current occupancy for every edge into the slot whose index equals that edge’s EdgeIndex.0. It must not depend on pre-existing contents of out.

  • refresh_occupancies_for_node is a partial, in-place refresh: it MUST update only entries for edges incident to node I (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§

Source

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.

Source

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.

Source

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).

Source

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).

Source

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 in 0..EDGE_COUNT.
§Errors

Returns a GraphError if E is out of range or the occupancy cannot be sampled.

Source

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 whose EdgeIndex.0 == k.
  • Must not depend on prior out contents.
  • On per-edge sampling failure, return Err(GraphError::OccupancySampleFailed(edge_idx)).
Source

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 edge k is upstream or downstream of node I.
  • MUST NOT modify any other out[k].
  • If node I has no incident edges, this is a no-op that returns Ok(()).
  • On sampling failure for any incident edge, return Err(GraphError::OccupancySampleFailed(edge_idx)).
Source

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§

Source

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.

Source

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>,

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 in 0..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.

Implementors§

Source§

impl<SrcClk: PlatformClock + Send + 'static> GraphApi<3, 3> for TestPipelineStd<SrcClk>

Source§

impl<SrcClk: PlatformClock> GraphApi<3, 3> for TestPipeline<SrcClk>