pub struct Middleware<State, Handler> { /* private fields */ }Expand description
Owns user state and middleware as one reusable interception unit.
Implementations§
Source§impl<State, Handler> Middleware<State, Handler>
impl<State, Handler> Middleware<State, Handler>
Sourcepub const fn new(state: State, handler: Handler) -> Self
pub const fn new(state: State, handler: Handler) -> Self
Creates middleware with its connection- or application-local state.
Sourcepub const fn state_mut(&mut self) -> &mut State
pub const fn state_mut(&mut self) -> &mut State
Mutably borrows the accumulated user state.
Sourcepub const fn handler_mut(&mut self) -> &mut Handler
pub const fn handler_mut(&mut self) -> &mut Handler
Mutably borrows the middleware implementation.
Sourcepub fn into_parts(self) -> (State, Handler)
pub fn into_parts(self) -> (State, Handler)
Separates the accumulated state from its middleware implementation.
Sourcepub fn intercept<Message>(
&mut self,
message: Message,
) -> Result<Message, Handler::Error>where
Handler: MessageMiddleware<Message, State>,
pub fn intercept<Message>(
&mut self,
message: Message,
) -> Result<Message, Handler::Error>where
Handler: MessageMiddleware<Message, State>,
Sourcepub fn intercept_typed<Role, Phase, Message>(
&mut self,
message: Message,
) -> Result<Message, Handler::Error>where
Handler: TypedMiddleware<Role, Phase, Message, State>,
pub fn intercept_typed<Role, Phase, Message>(
&mut self,
message: Message,
) -> Result<Message, Handler::Error>where
Handler: TypedMiddleware<Role, Phase, Message, State>,
Intercepts a message whose role and legal protocol phase are type indexed.
This operation performs no dynamic protocol-state check: Role, Phase,
and the generated Message type are selected together by the typed caller.
Wire-shape validation remains a separate runtime boundary after converting
the result back into its decoded wire representation.
§Errors
Returns the middleware’s policy-defined error.
Sourcepub fn intercept_checked<Message, ProtocolState>(
&mut self,
protocol_state: &ProtocolState,
message: Message,
) -> Result<Message, InterceptError<Handler::Error, Message>>where
Message: ReconstructableMessage,
Handler: MessageMiddleware<Message, State>,
ProtocolState: AcceptsMessage<Message>,
pub fn intercept_checked<Message, ProtocolState>(
&mut self,
protocol_state: &ProtocolState,
message: Message,
) -> Result<Message, InterceptError<Handler::Error, Message>>where
Message: ReconstructableMessage,
Handler: MessageMiddleware<Message, State>,
ProtocolState: AcceptsMessage<Message>,
Intercepts a message and checks the result against protocol_state at runtime.
The compiler enforces the message direction and requires ProtocolState
to implement AcceptsMessage for that message type. The replacement’s
concrete variant and the supplied generated crate::grammar runtime
state value are dynamic, however, so protocol legality and wire
reconstructability are checked at runtime after the complete middleware
chain. Call this immediately before projecting and advancing the same
protocol state.
§Errors
Returns a middleware policy error, or the unchanged replacement when it
is not legal in protocol_state.
Trait Implementations§
Source§impl<State: Clone, Handler: Clone> Clone for Middleware<State, Handler>
impl<State: Clone, Handler: Clone> Clone for Middleware<State, Handler>
Source§fn clone(&self) -> Middleware<State, Handler>
fn clone(&self) -> Middleware<State, Handler>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more