Skip to main content

Middleware

Struct Middleware 

Source
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>

Source

pub const fn new(state: State, handler: Handler) -> Self

Creates middleware with its connection- or application-local state.

Source

pub const fn state(&self) -> &State

Borrows the accumulated user state.

Source

pub const fn state_mut(&mut self) -> &mut State

Mutably borrows the accumulated user state.

Source

pub const fn handler(&self) -> &Handler

Borrows the middleware implementation.

Source

pub const fn handler_mut(&mut self) -> &mut Handler

Mutably borrows the middleware implementation.

Source

pub fn into_parts(self) -> (State, Handler)

Separates the accumulated state from its middleware implementation.

Source

pub async fn intercept<Message>( &mut self, message: Message, ) -> Result<Message, Handler::Error>
where Handler: MessageMiddleware<Message, State>,

Intercepts one owned message.

§Errors

Returns the middleware’s policy-defined error.

Source

pub async 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.

Source

pub async 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>

Source§

fn clone(&self) -> Middleware<State, Handler>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<State: Copy, Handler: Copy> Copy for Middleware<State, Handler>

Source§

impl<State: Debug, Handler: Debug> Debug for Middleware<State, Handler>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<State: Eq, Handler: Eq> Eq for Middleware<State, Handler>

Source§

impl<State: PartialEq, Handler: PartialEq> PartialEq for Middleware<State, Handler>

Source§

fn eq(&self, other: &Middleware<State, Handler>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<State: PartialEq, Handler: PartialEq> StructuralPartialEq for Middleware<State, Handler>

Auto Trait Implementations§

§

impl<State, Handler> Freeze for Middleware<State, Handler>
where State: Freeze, Handler: Freeze,

§

impl<State, Handler> RefUnwindSafe for Middleware<State, Handler>
where State: RefUnwindSafe, Handler: RefUnwindSafe,

§

impl<State, Handler> Send for Middleware<State, Handler>
where State: Send, Handler: Send,

§

impl<State, Handler> Sync for Middleware<State, Handler>
where State: Sync, Handler: Sync,

§

impl<State, Handler> Unpin for Middleware<State, Handler>
where State: Unpin, Handler: Unpin,

§

impl<State, Handler> UnsafeUnpin for Middleware<State, Handler>
where State: UnsafeUnpin, Handler: UnsafeUnpin,

§

impl<State, Handler> UnwindSafe for Middleware<State, Handler>
where State: UnwindSafe, Handler: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Handler> MessageMiddlewareExt for Handler

Source§

fn then<Next>(self, next: Next) -> Then<Self, Next>

Runs this value followed by next whenever both implement middleware for the intercepted message and state types.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.