pub struct FnMiddleware<F> { /* private fields */ }Expand description
Function-based Middleware
Helper to create middleware from async functions without implementing
the full Middleware trait.
Implementations§
Source§impl<F> FnMiddleware<F>
impl<F> FnMiddleware<F>
Sourcepub fn new(func: F) -> Arc<Self>
pub fn new(func: F) -> Arc<Self>
Creates a new function-based middleware.
§Examples
use wsforge::prelude::*;
let middleware = FnMiddleware::new(|msg, conn, state, ext, mut next| async move {
println!("Before handler");
let response = next.run(msg, conn, state, ext).await?;
println!("After handler");
Ok(response)
});Trait Implementations§
Source§impl<F, Fut> Middleware for FnMiddleware<F>
impl<F, Fut> Middleware for FnMiddleware<F>
Source§fn handle<'life0, 'async_trait>(
&'life0 self,
message: Message,
conn: Connection,
state: AppState,
extensions: Extensions,
next: Next,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle<'life0, 'async_trait>(
&'life0 self,
message: Message,
conn: Connection,
state: AppState,
extensions: Extensions,
next: Next,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Handle a message and optionally pass it to the next middleware. Read more
Auto Trait Implementations§
impl<F> Freeze for FnMiddleware<F>where
F: Freeze,
impl<F> RefUnwindSafe for FnMiddleware<F>where
F: RefUnwindSafe,
impl<F> Send for FnMiddleware<F>where
F: Send,
impl<F> Sync for FnMiddleware<F>where
F: Sync,
impl<F> Unpin for FnMiddleware<F>where
F: Unpin,
impl<F> UnwindSafe for FnMiddleware<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more