xitca_web/handler/types/
path.rs1use core::ops::Deref;
4
5use crate::{context::WebContext, error::Error, handler::FromRequest};
6
7#[derive(Debug)]
8pub struct PathRef<'a>(pub &'a str);
9
10impl Deref for PathRef<'_> {
11 type Target = str;
12
13 fn deref(&self) -> &Self::Target {
14 self.0
15 }
16}
17
18impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathRef<'a> {
19 type Type<'b> = PathRef<'b>;
20 type Error = Error;
21
22 #[inline]
23 async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result<Self, Self::Error> {
24 Ok(PathRef(ctx.req().uri().path()))
25 }
26}
27
28#[derive(Debug)]
29pub struct PathOwn(pub String);
30
31impl Deref for PathOwn {
32 type Target = str;
33
34 fn deref(&self) -> &Self::Target {
35 self.0.as_str()
36 }
37}
38
39impl<'a, 'r, C, B> FromRequest<'a, WebContext<'r, C, B>> for PathOwn {
40 type Type<'b> = PathOwn;
41 type Error = Error;
42
43 #[inline]
44 async fn from_request(ctx: &'a WebContext<'r, C, B>) -> Result<Self, Self::Error> {
45 Ok(PathOwn(ctx.req().uri().path().to_string()))
46 }
47}