Struct ntex::web::types::Path [−][src]
pub struct Path<T> { /* fields omitted */ }
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
impl<T> Path<T>
[src]
impl<T> Path<T>
[src]pub fn into_inner(self) -> T
[src]
pub fn into_inner(self) -> T
[src]Deconstruct to an inner value
Trait Implementations
impl<T, Err: ErrorRenderer> FromRequest<Err> for Path<T> where
T: DeserializeOwned,
[src]
impl<T, Err: ErrorRenderer> FromRequest<Err> for Path<T> where
T: DeserializeOwned,
[src]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 ); }
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]Convert request to a Self
fn extract(req: &HttpRequest) -> Self::Future
[src]
fn extract(req: &HttpRequest) -> Self::Future
[src]Convert request to a Self Read more
impl<T: Ord> Ord for Path<T>
[src]
impl<T: Ord> Ord for Path<T>
[src]impl<T: PartialOrd> PartialOrd<Path<T>> for Path<T>
[src]
impl<T: PartialOrd> PartialOrd<Path<T>> for Path<T>
[src]fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Path<T>) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<T: Eq> Eq for Path<T>
[src]
impl<T> StructuralEq for Path<T>
[src]
impl<T> StructuralPartialEq for Path<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Path<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Path<T> where
T: Send,
T: Send,
impl<T> Sync for Path<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Path<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Path<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]pub fn equivalent(&self, key: &K) -> bool
[src]
pub fn equivalent(&self, key: &K) -> bool
[src]Compare self to key
and return true
if they are equal.
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self