pub struct Extension<T>(pub Arc<T>);Expand description
Extractor for custom extension data.
Retrieves data that was previously stored in extensions by middleware or other handlers.
§Examples
§Authentication Data
use wsforge::prelude::*;
use std::sync::Arc;
#[derive(Clone)]
struct AuthData {
user_id: u64,
role: String,
}
async fn protected_handler(Extension(auth): Extension<AuthData>) -> Result<String> {
Ok(format!("User {} with role {}", auth.user_id, auth.role))
}Tuple Fields§
§0: Arc<T>Trait Implementations§
Source§impl<T: Send + Sync + Clone + 'static> FromMessage for Extension<T>
impl<T: Send + Sync + Clone + 'static> FromMessage for Extension<T>
Source§fn from_message<'life0, 'life1, 'life2, 'life3, 'async_trait>(
_message: &'life0 Message,
_conn: &'life1 Connection,
_state: &'life2 AppState,
extensions: &'life3 Extensions,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn from_message<'life0, 'life1, 'life2, 'life3, 'async_trait>(
_message: &'life0 Message,
_conn: &'life1 Connection,
_state: &'life2 AppState,
extensions: &'life3 Extensions,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Extracts
Self from the message and context. Read moreAuto Trait Implementations§
impl<T> Freeze for Extension<T>
impl<T> RefUnwindSafe for Extension<T>where
T: RefUnwindSafe,
impl<T> Send for Extension<T>
impl<T> Sync for Extension<T>
impl<T> Unpin for Extension<T>
impl<T> UnwindSafe for Extension<T>where
T: RefUnwindSafe,
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