pub struct Path<T>(pub T);Expand description
Extracts path parameters from the URL.
Supports three extraction modes:
Single parameter — parses one :param into any type that implements FromStr:
ⓘ
#[get("/users/:id")]
async fn get_user(id: Path<u64>) -> String {
format!("User ID: {}", *id)
}Tuple — extracts multiple parameters in declaration order (left to right in the pattern):
ⓘ
#[get("/orgs/:org_id/teams/:team_id")]
async fn get_team(Path((org_id, team_id)): Path<(u64, u64)>) -> String {
format!("org={} team={}", org_id, team_id)
}Three or more — same tuple syntax:
ⓘ
#[get("/orgs/:org_id/teams/:team_id/members/:member_id")]
async fn get_member(Path((org_id, team_id, member_id)): Path<(u64, u64, u64)>) -> String {
format!("org={} team={} member={}", org_id, team_id, member_id)
}Returns 400 Bad Request if a parameter is missing or cannot be parsed.
Tuple Fields§
§0: TImplementations§
Source§impl<T> Path<T>
impl<T> Path<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes the extractor and returns the inner value.
Trait Implementations§
Source§impl<T: DeserializeOwned + Send> FromRequestParts for Path<T>
impl<T: DeserializeOwned + Send> FromRequestParts for Path<T>
Source§async fn from_request_parts(
_parts: &Parts,
params: &PathParams,
_state: &Arc<AppState>,
) -> Result<Self, Error>
async fn from_request_parts( _parts: &Parts, params: &PathParams, _state: &Arc<AppState>, ) -> Result<Self, Error>
Extract the value from request parts.
Auto 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> UnsafeUnpin for Path<T>where
T: UnsafeUnpin,
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
Source§impl<T> FromRequest for Twhere
T: FromRequestParts,
impl<T> FromRequest for Twhere
T: FromRequestParts,
Source§async fn from_request(
req: Request<Incoming>,
params: &PathParams,
state: &Arc<AppState>,
) -> Result<T, Error>
async fn from_request( req: Request<Incoming>, params: &PathParams, state: &Arc<AppState>, ) -> Result<T, Error>
Extract the value from the request.