pub struct Path<T>(pub T);Expand description
Extracts a single path parameter, parsed into T.
For a route such as "/users/{id}", Path::<u64> reads the first captured
parameter ({id}). It reads positionally, so it is intended for routes with
exactly one path parameter; for routes with several, read each by name with
Call::param. Extraction fails with 400 Bad Request
if there is no parameter or the value does not parse into T.
use churust_core::{Churust, Path, TestClient};
let app = Churust::server()
.routing(|r| {
r.get("/double/{n}", |Path(n): Path<i64>| async move {
format!("{}", n * 2)
});
})
.build();
let res = TestClient::new(app).get("/double/21").send().await;
assert_eq!(res.text(), "42");Tuple Fields§
§0: TThe parsed path parameter value.
Trait Implementations§
Source§impl<T> FromCallParts for Path<T>where
T: DeserializeOwned + Send,
impl<T> FromCallParts for Path<T>where
T: DeserializeOwned + Send,
Source§impl<T> OptionalFromCallParts for Path<T>where
T: DeserializeOwned + Send,
Absent means the route captured no parameters. A parameter that is present
but does not parse into T is an error — reporting None there would claim
the URL had no such parameter at all.
impl<T> OptionalFromCallParts for Path<T>where
T: DeserializeOwned + Send,
Absent means the route captured no parameters. A parameter that is present
but does not parse into T is an error — reporting None there would claim
the URL had no such parameter at all.
Source§fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn from_call_parts_opt<'life0, 'async_trait>(
call: &'life0 mut Call,
) -> Pin<Box<dyn Future<Output = Result<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Build
Self, or Ok(None) when the input is absent. Reserve Err for
input that was supplied and is wrong.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> UnsafeUnpin for Path<T>where
T: UnsafeUnpin,
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