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§
Required Methods§
Sourcefn open(&mut self) -> Result<(), Self::Error>
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.
Sourcefn try_produce(&mut self) -> Option<(usize, Message<OutP>)>
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
portmust be< OUT.
Sourcefn ingress_occupancy(&self) -> EdgeOccupancy
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.
Sourcefn peek_ingress_creation_tick(&self, item_index: usize) -> Option<u64>
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.
Sourcefn output_acceptance(&self) -> [PlacementAcceptance; OUT]
fn output_acceptance(&self) -> [PlacementAcceptance; OUT]
Return output placement acceptances for zero-copy compatibility.
Sourcefn capabilities(&self) -> NodeCapabilities
fn capabilities(&self) -> NodeCapabilities
Describe source capabilities (device streams, degrade tiers, etc.).
Sourcefn policy(&self) -> NodePolicy
fn policy(&self) -> NodePolicy
Provide the node policy bundle (batching/budget/deadlines).
Sourcefn ingress_policy(&self) -> EdgePolicy
fn ingress_policy(&self) -> EdgePolicy
Provude the ingress edge policy for this source node.
Provided Methods§
Sourcefn into_sourcenode(self, policy: NodePolicy) -> SourceNode<Self, OutP, OUT>where
Self: Sized,
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.