mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-07 00:00:12 +02:00
Implement Deref and DerefMut for built-in extractors (#1922)
This commit is contained in:
@@ -3,7 +3,6 @@ use axum::{
|
||||
extract::{Extension, FromRequestParts},
|
||||
};
|
||||
use http::request::Parts;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// Cache results of other extractors.
|
||||
///
|
||||
@@ -108,19 +107,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Cached<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> DerefMut for Cached<T> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
axum_core::__impl_deref!(Cached);
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
@@ -7,7 +7,7 @@ use axum::{
|
||||
};
|
||||
use http::{Request, StatusCode};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::{fmt, ops::Deref};
|
||||
use std::fmt;
|
||||
|
||||
/// Extractor that deserializes `application/x-www-form-urlencoded` requests
|
||||
/// into some type.
|
||||
@@ -43,13 +43,7 @@ use std::{fmt, ops::Deref};
|
||||
#[cfg(feature = "form")]
|
||||
pub struct Form<T>(pub T);
|
||||
|
||||
impl<T> Deref for Form<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
axum_core::__impl_deref!(Form);
|
||||
|
||||
#[async_trait]
|
||||
impl<T, S, B> FromRequest<S, B> for Form<T>
|
||||
|
||||
@@ -6,7 +6,7 @@ use axum::{
|
||||
};
|
||||
use http::{request::Parts, StatusCode};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::{fmt, ops::Deref};
|
||||
use std::fmt;
|
||||
|
||||
/// Extractor that deserializes query strings into some type.
|
||||
///
|
||||
@@ -73,13 +73,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Deref for Query<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
axum_core::__impl_deref!(Query);
|
||||
|
||||
/// Rejection used for [`Query`].
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user