Skip to main content

Source

Trait Source 

Source
pub trait Source<OutP, const OUT: usize>
where OutP: Payload,
{ type Error; // Required methods fn open(&mut self) -> Result<(), Self::Error>; fn try_produce(&mut self) -> Option<(usize, Message<OutP>)>; fn ingress_occupancy(&self) -> EdgeOccupancy; fn peek_ingress_creation_tick(&self, item_index: usize) -> Option<u64>; fn output_acceptance(&self) -> [PlacementAcceptance; OUT]; fn capabilities(&self) -> NodeCapabilities; fn policy(&self) -> NodePolicy; fn ingress_policy(&self) -> EdgePolicy; // Provided method fn into_sourcenode(self, policy: NodePolicy) -> SourceNode<Self, OutP, OUT> where Self: Sized { ... } }
Expand description

Uniform contract for source implementations (0 inputs / ≥1 outputs).

Source types produce messages for downstream nodes and report ingress pressure (items/bytes before the source, e.g., device FIFO depth), allowing schedulers to decide when to poll the source.

§Type Parameters

  • OutP — Payload type for produced messages.
  • OUT — Number of output ports on the source node.

Required Associated Types§

Source

type Error

Source-specific error type for open().

Required Methods§

Source

fn open(&mut self) -> Result<(), Self::Error>

Prepare the source for production (e.g., open device, init driver).

Called from Node::initialize. Must be idempotent or fail safely if called multiple times by a higher layer.

Source

fn try_produce(&mut self) -> Option<(usize, Message<OutP>)>

Attempt to produce exactly one (port, message) pair.

Return None if there is nothing to produce right now.

§Contract
  • Must be non-blocking.
  • The returned port must be < OUT.
Source

fn ingress_occupancy(&self) -> EdgeOccupancy

Report ingress pressure (items/bytes before the source).

Implementations should be non-blocking and may read hardware counters, driver FIFOs, ring buffer lengths, or cached snapshots.

policy is provided so implementations can compute a consistent EdgeOccupancy.watermark using the same thresholds as real edges.

Source

fn peek_ingress_creation_tick(&self, item_index: usize) -> Option<u64>

Return the creation tick of the index’th ingress item (0-based) without dequeuing it. Implementations must be non-blocking and non-destructive. Return None if metadata is unavailable or index is out-of-range.

Source

fn output_acceptance(&self) -> [PlacementAcceptance; OUT]

Return output placement acceptances for zero-copy compatibility.

Source

fn capabilities(&self) -> NodeCapabilities

Describe source capabilities (device streams, degrade tiers, etc.).

Source

fn policy(&self) -> NodePolicy

Provide the node policy bundle (batching/budget/deadlines).

Source

fn ingress_policy(&self) -> EdgePolicy

Provude the ingress edge policy for this source node.

Provided Methods§

Source

fn into_sourcenode(self, policy: NodePolicy) -> SourceNode<Self, OutP, OUT>
where Self: Sized,

Convenience: wrap this source in a SourceNode with the provided policy.

This is a zero-overhead helper so all Source implementations can be lifted into a node uniformly without each impl writing a custom helper.

Implementors§

Source§

impl<Clock, const BACKLOG_CAP: usize> Source<Tensor<u32, TEST_TENSOR_ELEMENT_COUNT, 2>, 1> for TestCounterSourceTensor<Clock, BACKLOG_CAP>
where Clock: PlatformClock,