Struct actix_web::Path

source ·
pub struct Path<T> { /* private fields */ }
Expand description

Extract typed information from the request’s path. Information from the path is URL decoded. Decoding of special characters can be disabled through PathConfig.

Example

use actix_web::{http, App, Path, Result};

/// extract path info from "/{username}/{count}/index.html" url
/// {username} - deserializes to a String
/// {count} -  - deserializes to a u32
fn index(info: Path<(String, u32)>) -> Result<String> {
    Ok(format!("Welcome {}! {}", info.0, info.1))
}

fn main() {
    let app = App::new().resource(
        "/{username}/{count}/index.html", // <- define path parameters
        |r| r.method(http::Method::GET).with(index),
    ); // <- use `with` extractor
}

It is possible to extract path information to a specific type that implements Deserialize trait from serde.

#[macro_use] extern crate serde_derive;
use actix_web::{http, App, Path, Result};

#[derive(Deserialize)]
struct Info {
    username: String,
}

/// extract path info using serde
fn index(info: Path<Info>) -> Result<String> {
    Ok(format!("Welcome {}!", info.username))
}

fn main() {
    let app = App::new().resource(
        "/{username}/index.html", // <- define path parameters
        |r| r.method(http::Method::GET).with(index),
    ); // <- use `with` extractor
}

Implementations

Deconstruct to an inner value

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Configuration for conversion process
Future that resolves to a Self
Convert request to a Self
Convert request to a Self Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.