Implement Deref and DerefMut for built-in extractors (#1922)

This commit is contained in:
David Pedersen
2023-04-10 07:18:35 +00:00
committed by GitHub
parent 43b2d52403
commit 352cf9a266
17 changed files with 67 additions and 112 deletions
+1 -14
View File
@@ -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 {
+2 -8
View File
@@ -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>
+2 -8
View File
@@ -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`].
///