# actix_web::Path - Rust
API documentation for the Rust `Path` struct in crate `actix_web`.
Keywords: rust, rustlang, rust-lang, Path

# Struct actix_web::Path [−] [src]

    pub struct Path<T> { /* fields omitted */ }

Extract typed information from the request's path.

## 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
    }

## Methods

###

`impl<T> Path<T>`

[src]

####

`pub fn into_inner(self) -> T`

[src]

Deconstruct to an inner value

## Trait Implementations

###

`impl<T: PartialEq> PartialEq 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: Eq> Eq for Path<T>`

[src]

###

`impl<T: PartialOrd> PartialOrd 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

####

`fn lt(&self, other: &Path<T>) -> bool`

[src]

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

####

`fn le(&self, other: &Path<T>) -> bool`

[src]

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

####

`fn gt(&self, other: &Path<T>) -> bool`

[src]

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

####

`fn ge(&self, other: &Path<T>) -> bool`

[src]

This method tests greater than or equal to (for `self` and `other`) and is used by the `>=` operator. 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

####

`fn max(self, other: Self) -> Self`

1.21.0
[src]

Compares and returns the maximum of two values. Read more

####

`fn min(self, other: Self) -> Self`

1.21.0
[src]

Compares and returns the minimum of two values. Read more

###

`impl<T> AsRef<T> for Path<T>`

[src]

####
ⓘImportant traits for &'a mut R

### Important traits for &'a mut R

`impl<'a, R> Read for &'a mut R where
R: Read + ?Sized, impl<'a, W> Write for &'a mut W where
W: Write + ?Sized, impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;`

`fn as_ref(&self) -> &T`

[src]

Performs the conversion.

###

`impl<T> Deref for Path<T>`

[src]

#### `type Target = T`

The resulting type after dereferencing.

####
ⓘImportant traits for &'a mut R

### Important traits for &'a mut R

`impl<'a, R> Read for &'a mut R where
R: Read + ?Sized, impl<'a, W> Write for &'a mut W where
W: Write + ?Sized, impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;`

`fn deref(&self) -> &T`

[src]

Dereferences the value.

###

`impl<T> DerefMut for Path<T>`

[src]

####
ⓘImportant traits for &'a mut R

### Important traits for &'a mut R

`impl<'a, R> Read for &'a mut R where
R: Read + ?Sized, impl<'a, W> Write for &'a mut W where
W: Write + ?Sized, impl<'a, I> Iterator for &'a mut I where
I: Iterator + ?Sized, type Item = <I as Iterator>::Item;`

`fn deref_mut(&mut self) -> &mut T`

[src]

Mutably dereferences the value.

###

`impl<T, S> FromRequest<S> for Path<T> where T: DeserializeOwned,`

[src]

#### `type Config = ()`

Configuration for conversion process

#### `type Result = Result<Self, Error>`

Future that resolves to a Self

####

`fn from_request(req: &HttpRequest<S>, _: &Self::Config) -> Self::Result`

[src]

Convert request to a Self

####

`fn extract(req: &HttpRequest<S>) -> Self::Result`

[src]

Convert request to a Self Read more

###

`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: Display> Display for Path<T>`

[src]

####

`fn fmt(&self, f: &mut Formatter) -> Result`

[src]

Formats the value using the given formatter. Read more

## Auto Trait Implementations

###

`impl<T> Send for Path<T> where T: Send,`

###

`impl<T> Sync for Path<T> where T: Sync,`

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)