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]

pub fn into_inner(self) -> T[src]

Deconstruct to an inner value

Trait Implementations

impl<T> AsRef<T> for Path<T>[src]

fn as_ref(&self) -> &T[src]

Performs the conversion.

impl<T: Debug> Debug for Path<T>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> Deref for Path<T>[src]

type Target = T

The resulting type after dereferencing.

fn deref(&self) -> &T[src]

Dereferences the value.

impl<T> DerefMut for Path<T>[src]

fn deref_mut(&mut self) -> &mut T[src]

Mutably dereferences the value.

impl<T: Display> Display for Path<T>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T> From<T> for Path<T>[src]

fn from(inner: T) -> Path<T>[src]

Performs the conversion.

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
    );
}

type Error = PathError

The associated error which can be returned.

type Future = Ready<Self, Self::Error>

Future that resolves to a Self

fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future[src]

Convert request to a Self

fn extract(req: &HttpRequest) -> Self::Future[src]

Convert request to a Self Read more

impl<T: Ord> Ord for Path<T>[src]

fn cmp(&self, other: &Path<T>) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl<T: PartialEq> PartialEq<Path<T>> for Path<T>[src]

fn eq(&self, other: &Path<T>) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Path<T>) -> bool[src]

This method tests for !=.

impl<T: PartialOrd> PartialOrd<Path<T>> for Path<T>[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]

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]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater 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

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[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]

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

impl<T> From<!> for T[src]

pub fn from(t: !) -> T[src]

Performs the conversion.

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[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]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToString for T where
    T: Display + ?Sized
[src]

pub default fn to_string(&self) -> String[src]

Converts the given value to a String. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.