pub struct Path<T>(pub T);Expand description
Extractor for path parameters.
Extracts typed parameters from the request path. The type must implement
serde::Deserialize and be stored in extensions by routing middleware.
§Examples
§Single Parameter
use wsforge::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct UserId(u64);
async fn get_user(Path(UserId(id)): Path<UserId>) -> Result<String> {
Ok(format!("Getting user {}", id))
}§Multiple Parameters
use wsforge::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct RoomParams {
room_id: String,
user_id: u64,
}
async fn join_room(Path(params): Path<RoomParams>) -> Result<String> {
Ok(format!("User {} joining room {}", params.user_id, params.room_id))
}Tuple Fields§
§0: TTrait Implementations§
Source§impl<T: DeserializeOwned + Send + Sync + Clone + 'static> FromMessage for Path<T>
impl<T: DeserializeOwned + Send + Sync + Clone + 'static> FromMessage for Path<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 Path<T>where
T: Freeze,
impl<T> RefUnwindSafe for Path<T>where
T: RefUnwindSafe,
impl<T> Send for Path<T>where
T: Send,
impl<T> Sync for Path<T>where
T: Sync,
impl<T> Unpin for Path<T>where
T: Unpin,
impl<T> UnwindSafe for Path<T>where
T: 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