Struct ajars_actix_web::actix_web::web::Path [−][src]
pub struct Path<T>(_);
Expand description
Extract typed data from request path segments.
Use PathConfig
to configure extraction process.
Examples
use actix_web::{get, web};
// extract path info from "/{name}/{count}/index.html" into tuple
// {name} - deserialize a String
// {count} - deserialize a u32
#[get("/{name}/{count}/index.html")]
async fn index(path: web::Path<(String, u32)>) -> String {
let (name, count) = path.into_inner();
format!("Welcome {}! {}", name, count)
}
Path segments also can be deserialized into any type that implements serde::Deserialize
.
Path segment labels will be matched with struct field names.
use actix_web::{get, web};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
name: String,
}
// extract `Info` from a path using serde
#[get("/{name}")]
async fn index(info: web::Path<Info>) -> String {
format!("Welcome {}!", info.name)
}
Implementations
Unwrap into inner T
value.
Trait Implementations
See here for example of usage as an extractor.
Future that resolves to a Self.
type Config = PathConfig
type Config = PathConfig
Configuration for this extractor.
pub fn from_request(
req: &HttpRequest,
&mut Payload<Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>> + 'static, Global>>>
) -> <Path<T> as FromRequest>::Future
pub fn from_request(
req: &HttpRequest,
&mut Payload<Pin<Box<dyn Stream<Item = Result<Bytes, PayloadError>> + 'static, Global>>>
) -> <Path<T> as FromRequest>::Future
Create a Self from request parts asynchronously.
Create a Self from request head asynchronously. 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