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>
impl<T> FromCallParts 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> 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