pub struct Path<D>(pub D);Expand description
An extractor that extracts data from the URL params.
The extractor is generic over a type that implements
serde::de::DeserializeOwned.
§Examples
use cot::html::Html;
use cot::request::extractors::{FromRequest, Path};
use cot::request::{Request, RequestExt};
use cot::router::{Route, Router};
use cot::test::TestRequestBuilder;
async fn my_handler(Path(my_param): Path<String>) -> Html {
Html::new(format!("Hello {my_param}!"))
}
let router = Router::with_urls([Route::with_handler_and_name(
"/{my_param}/",
my_handler,
"home",
)]);
let request = TestRequestBuilder::get("/world/")
.router(router.clone())
.build();
assert_eq!(
router
.handle(request)
.await?
.into_body()
.into_bytes()
.await?,
"Hello world!"
);Tuple Fields§
§0: DTrait Implementations§
Source§impl<D: JsonSchema> ApiOperationPart for Path<D>
Available on crate feature openapi only.
impl<D: JsonSchema> ApiOperationPart for Path<D>
Available on crate feature
openapi only.Source§fn modify_api_operation(
operation: &mut Operation,
route_context: &RouteContext<'_>,
schema_generator: &mut SchemaGenerator,
)
fn modify_api_operation( operation: &mut Operation, route_context: &RouteContext<'_>, schema_generator: &mut SchemaGenerator, )
Modify the OpenAPI operation object. Read more
Source§impl<D: DeserializeOwned> FromRequestHead for Path<D>
impl<D: DeserializeOwned> FromRequestHead for Path<D>
Source§async fn from_request_head(head: &RequestHead) -> Result<Self>
async fn from_request_head(head: &RequestHead) -> Result<Self>
Extracts data from the request head. Read more
Source§impl<D: Ord> Ord for Path<D>
impl<D: Ord> Ord for Path<D>
Source§impl<D: PartialOrd> PartialOrd for Path<D>
impl<D: PartialOrd> PartialOrd for Path<D>
impl<D: Copy> Copy for Path<D>
impl<D: Eq> Eq for Path<D>
impl<D> StructuralPartialEq for Path<D>
Auto Trait Implementations§
impl<D> Freeze for Path<D>where
D: Freeze,
impl<D> RefUnwindSafe for Path<D>where
D: RefUnwindSafe,
impl<D> Send for Path<D>where
D: Send,
impl<D> Sync for Path<D>where
D: Sync,
impl<D> Unpin for Path<D>where
D: Unpin,
impl<D> UnwindSafe for Path<D>where
D: 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoField<Auto<T>> for T
impl<T> IntoField<Auto<T>> for T
Source§fn into_field(self) -> Auto<T>
fn into_field(self) -> Auto<T>
Available on crate feature
db only.Converts the type to the field type.