ndn_pipeline/stage.rs
1use crate::action::Action;
2use crate::context::PacketContext;
3
4/// A single stage in the NDN forwarding pipeline.
5///
6/// Stages are fixed at build time (not runtime-configurable) so the compiler
7/// can inline and optimise the dispatch loop for the known concrete types.
8///
9/// `process` takes `PacketContext` by value. `Action::Continue` returns it
10/// to the runner. All other actions consume it, making use-after-hand-off
11/// a compile error.
12pub trait PipelineStage: Send + Sync + 'static {
13 fn process(
14 &self,
15 ctx: PacketContext,
16 ) -> impl std::future::Future<Output = Result<Action, crate::action::DropReason>> + Send;
17}
18
19/// Object-safe wrapper around `PipelineStage` for runtime dispatch.
20///
21/// Used for stages that genuinely need dynamic dispatch (e.g., plugin stages).
22/// The built-in pipeline is monomorphised for zero-cost dispatch.
23pub type BoxedStage = Box<
24 dyn Fn(
25 PacketContext,
26 ) -> std::pin::Pin<
27 Box<dyn std::future::Future<Output = Result<Action, crate::action::DropReason>> + Send>,
28 > + Send
29 + Sync,
30>;