Skip to main content

MiddlewareStack

Struct MiddlewareStack 

Source
pub struct MiddlewareStack<S: AppState> { /* private fields */ }
Expand description

A composable stack of middleware layers.

This struct holds a collection of middleware that will be executed in order. Middleware are executed in the order they are added to the stack.

§Example

use binary_options_tools_core_pre::middleware::MiddlewareStack;

let mut stack = MiddlewareStack::new();
stack.add_layer(Box::new(LoggingMiddleware));
stack.add_layer(Box::new(StatisticsMiddleware::new()));

Implementations§

Source§

impl<S: AppState> MiddlewareStack<S>

Source

pub fn new() -> Self

Creates a new empty middleware stack.

Source

pub fn add_layer( &mut self, middleware: Box<dyn WebSocketMiddleware<S> + Send + Sync>, )

Adds a middleware layer to the stack.

Middleware will be executed in the order they are added.

Source

pub async fn on_send(&self, message: &Message, context: &MiddlewareContext<S>)

Executes all middleware for an outgoing message.

§Arguments
  • message: The message being sent
  • context: Context information
§Behavior

All middleware will be executed even if some fail. Errors are logged but do not prevent other middleware from running.

Source

pub async fn on_receive( &self, message: &Message, context: &MiddlewareContext<S>, )

Executes all middleware for an incoming message.

§Arguments
  • message: The message that was received
  • context: Context information
§Behavior

All middleware will be executed even if some fail. Errors are logged but do not prevent other middleware from running.

Source

pub async fn on_connect(&self, context: &MiddlewareContext<S>)

Executes all middleware for connection establishment.

§Arguments
  • context: Context information
§Behavior

All middleware will be executed even if some fail. Errors are logged but do not prevent other middleware from running.

Source

pub async fn on_disconnect(&self, context: &MiddlewareContext<S>)

Executes all middleware for connection loss.

§Arguments
  • context: Context information
§Behavior

All middleware will be executed even if some fail. Errors are logged but do not prevent other middleware from running.

Source

pub async fn record_connection_attempt(&self, context: &MiddlewareContext<S>)

Record a connection attempt across all middleware

Source

pub async fn record_connection_failure( &self, context: &MiddlewareContext<S>, reason: Option<String>, )

Record a connection failure across all middleware

Source

pub fn len(&self) -> usize

Returns the number of middleware layers in the stack.

Source

pub fn is_empty(&self) -> bool

Returns true if the stack is empty.

Trait Implementations§

Source§

impl<S: AppState> Default for MiddlewareStack<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more