pub struct Path<T> { /* private fields */ }
Expand description
Extract typed information from the request’s path.
PathConfig allows to configure extraction process.
§Example
use ntex::web;
/// extract path info from "/{username}/{count}/index.html" url
/// {username} - deserializes to a String
/// {count} - - deserializes to a u32
async fn index(info: web::types::Path<(String, u32)>) -> String {
format!("Welcome {}! {}", info.0, info.1)
}
fn main() {
let app = web::App::new().service(
web::resource("/{username}/{count}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- register handler with `Path` extractor
);
}
It is possible to extract path information to a specific type that
implements Deserialize
trait from serde.
use ntex::web;
#[derive(serde::Deserialize)]
struct Info {
username: String,
}
/// extract `Info` from a path using serde
async fn index(info: web::types::Path<Info>) -> Result<String, web::Error> {
Ok(format!("Welcome {}!", info.username))
}
fn main() {
let app = web::App::new().service(
web::resource("/{username}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- use handler with Path` extractor
);
}
Implementations§
source§impl<T> Path<T>
impl<T> Path<T>
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Deconstruct to an inner value
Trait Implementations§
source§impl<T, Err: ErrorRenderer> FromRequest<Err> for Path<T>where
T: DeserializeOwned,
impl<T, Err: ErrorRenderer> FromRequest<Err> for Path<T>where
T: DeserializeOwned,
Extract typed information from the request’s path.
§Example
use ntex::web;
/// extract path info from "/{username}/{count}/index.html" url
/// {username} - deserializes to a String
/// {count} - - deserializes to a u32
async fn index(info: web::types::Path<(String, u32)>) -> String {
format!("Welcome {}! {}", info.0, info.1)
}
fn main() {
let app = web::App::new().service(
web::resource("/{username}/{count}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- register handler with `Path` extractor
);
}
It is possible to extract path information to a specific type that
implements Deserialize
trait from serde.
use ntex::web;
#[derive(serde::Deserialize)]
struct Info {
username: String,
}
/// extract `Info` from a path using serde
async fn index(info: web::types::Path<Info>) -> Result<String, web::Error> {
Ok(format!("Welcome {}!", info.username))
}
fn main() {
let app = web::App::new().service(
web::resource("/{username}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- use handler with Path` extractor
);
}
source§async fn from_request(
req: &HttpRequest,
_: &mut Payload
) -> Result<Self, Self::Error>
async fn from_request( req: &HttpRequest, _: &mut Payload ) -> Result<Self, Self::Error>
Convert request to a Self
source§impl<T: Ord> Ord for Path<T>
impl<T: Ord> Ord for Path<T>
source§impl<T: PartialEq> PartialEq for Path<T>
impl<T: PartialEq> PartialEq for Path<T>
source§impl<T: PartialOrd> PartialOrd for Path<T>
impl<T: PartialOrd> PartialOrd for Path<T>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<T: Eq> Eq for Path<T>
impl<T> StructuralPartialEq for Path<T>
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> 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