mirror of https://github.com/tokio-rs/axum
Implement `Deref` for extractors (#56)
Fixes https://github.com/tokio-rs/axum/issues/54
This commit is contained in:
parent
100ecea581
commit
5407247e90
|
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Implement `Stream` for `WebSocket`.
|
||||
- Implement `Sink` for `WebSocket`.
|
||||
- Implement `Deref` most extractors.
|
||||
|
||||
## Breaking changes
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@ use serde::de::DeserializeOwned;
|
|||
use std::{
|
||||
collections::HashMap,
|
||||
convert::Infallible,
|
||||
ops::Deref,
|
||||
pin::Pin,
|
||||
str::FromStr,
|
||||
task::{Context, Poll},
|
||||
|
@ -596,6 +597,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Query<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor that deserializes `application/x-www-form-urlencoded` requests
|
||||
/// into some type.
|
||||
///
|
||||
|
@ -667,6 +676,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Form<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor that deserializes request bodies into some type.
|
||||
///
|
||||
/// `T` is expected to implement [`serde::Deserialize`].
|
||||
|
@ -731,6 +748,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Json<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn has_content_type<B>(
|
||||
req: &RequestParts<B>,
|
||||
expected_content_type: &str,
|
||||
|
@ -809,6 +834,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Extension<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<B> FromRequest<B> for Bytes
|
||||
where
|
||||
|
@ -1071,6 +1104,14 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T, const N: u64> Deref for ContentLengthLimit<T, N> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor that will get captures from the URL.
|
||||
///
|
||||
/// # Example
|
||||
|
@ -1219,6 +1260,14 @@ macro_rules! impl_parse_url {
|
|||
|
||||
impl_parse_url!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16);
|
||||
|
||||
impl<T> Deref for UrlParams<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
fn take_body<B>(req: &mut RequestParts<B>) -> Result<B, BodyAlreadyExtracted> {
|
||||
req.take_body().ok_or(BodyAlreadyExtracted)
|
||||
}
|
||||
|
@ -1274,6 +1323,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "headers")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "headers")))]
|
||||
impl<T> Deref for TypedHeader<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Extractor that extracts the raw query string, without parsing it.
|
||||
///
|
||||
/// # Example
|
||||
|
|
Loading…
Reference in New Issue