pub struct Next { /* private fields */ }Expand description
Opaque continuation passed to a Middleware. Calling Next::run
proceeds to the next middleware in the chain or to the Terminal if
the chain is exhausted.
The middleware chain is held as a shared Arc<[_]> walked with an index
cursor, so advancing the pipeline is a reference-count bump rather than a
per-dispatch allocation of the chain.
Implementations§
Source§impl Next
impl Next
Sourcepub fn new(
middlewares: impl Into<Arc<[Arc<dyn DynMiddleware>]>>,
terminal: Arc<dyn Terminal>,
) -> Self
pub fn new( middlewares: impl Into<Arc<[Arc<dyn DynMiddleware>]>>, terminal: Arc<dyn Terminal>, ) -> Self
Builds a new Next from a chain of middlewares and a terminal.
Middlewares are executed in the order they appear: the first one wraps
the second, which wraps the third, and so on. The chain accepts any
Into<Arc<[_]>>, so a freshly built Vec or a pre-shared Arc<[_]>
(cloned once per dispatch as a reference-count bump) both work.
Sourcepub async fn run(
self,
envelope: &MessageEnvelope,
ctx: &HandlerContext,
) -> Result<BoxOutput, HexeractError>
pub async fn run( self, envelope: &MessageEnvelope, ctx: &HandlerContext, ) -> Result<BoxOutput, HexeractError>
Advances the pipeline by one step.
§Errors
Returns the HexeractError produced by the next middleware in the
chain or by the Terminal when the chain is exhausted.