pub struct Path<T> { /* private fields */ }
Expand description
Extract typed information from the request’s path.
§Example
It is possible to extract path information to a specific type that
implements Deserialize
trait from serde and Validate
trait from validator.
use actix_web::{web, App, Error};
use serde::Deserialize;
use actix_web_validator::Path;
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 1))]
username: String,
}
/// extract `Info` from a path using serde
async fn index(info: Path<Info>) -> Result<String, Error> {
Ok(format!("Welcome {}!", info.username))
}
fn main() {
let app = App::new().service(
web::resource("/{username}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- use handler with Path` extractor
);
}
Implementations§
Source§impl<T> Path<T>
impl<T> Path<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Deconstruct to an inner value
Trait Implementations§
Source§impl<T> FromRequest for Path<T>where
T: DeserializeOwned + Validate,
Extract typed information from the request’s path.
impl<T> FromRequest for Path<T>where
T: DeserializeOwned + Validate,
Extract typed information from the request’s path.
§Example
It is possible to extract path information to a specific type that
implements Deserialize
trait from serde and Validate
trait from validator.
use actix_web::{web, App, Error};
use serde::Deserialize;
use actix_web_validator::Path;
use validator::Validate;
#[derive(Deserialize, Validate)]
struct Info {
#[validate(length(min = 1))]
username: String,
}
/// extract `Info` from a path using serde
async fn index(info: Path<Info>) -> Result<String, Error> {
Ok(format!("Welcome {}!", info.username))
}
fn main() {
let app = App::new().service(
web::resource("/{username}/index.html") // <- define path parameters
.route(web::get().to(index)) // <- use handler with Path` extractor
);
}
Source§impl<T: Ord> Ord for Path<T>
impl<T: Ord> Ord for Path<T>
Source§impl<T: PartialOrd> PartialOrd for Path<T>
impl<T: PartialOrd> PartialOrd for Path<T>
impl<T: Eq> Eq for Path<T>
impl<T> StructuralPartialEq for Path<T>
Auto Trait Implementations§
impl<T> Freeze for Path<T>where
T: Freeze,
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> ValidateIp for Twhere
T: ToString,
impl<T> ValidateIp for Twhere
T: ToString,
Source§fn validate_ipv4(&self) -> bool
fn validate_ipv4(&self) -> bool
Validates whether the given string is an IP V4
Source§fn validate_ipv6(&self) -> bool
fn validate_ipv6(&self) -> bool
Validates whether the given string is an IP V6
Source§fn validate_ip(&self) -> bool
fn validate_ip(&self) -> bool
Validates whether the given string is an IP