impl HasValidateArgs for all extractors
This commit is contained in:
18
src/extra.rs
18
src/extra.rs
@@ -236,9 +236,9 @@ pub mod query;
|
|||||||
#[cfg(feature = "extra_typed_path")]
|
#[cfg(feature = "extra_typed_path")]
|
||||||
pub mod typed_path;
|
pub mod typed_path;
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_extra::extract::{Cached, WithRejection};
|
use axum_extra::extract::{Cached, WithRejection};
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Cached<T> {
|
impl<T: Validate> HasValidate for Cached<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -248,6 +248,13 @@ impl<T: Validate> HasValidate for Cached<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Cached<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Validate, R> HasValidate for WithRejection<T, R> {
|
impl<T: Validate, R> HasValidate for WithRejection<T, R> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
fn get_validate(&self) -> &T {
|
fn get_validate(&self) -> &T {
|
||||||
@@ -255,6 +262,13 @@ impl<T: Validate, R> HasValidate for WithRejection<T, R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>, R> HasValidateArgs<'v> for WithRejection<T, R> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{Rejection, ValidTest};
|
use crate::tests::{Rejection, ValidTest};
|
||||||
|
|||||||
@@ -38,9 +38,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_extra::extract::Form;
|
use axum_extra::extract::Form;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Form<T> {
|
impl<T: Validate> HasValidate for Form<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -49,6 +49,13 @@ impl<T: Validate> HasValidate for Form<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Form<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
@@ -40,9 +40,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_extra::protobuf::Protobuf;
|
use axum_extra::protobuf::Protobuf;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Protobuf<T> {
|
impl<T: Validate> HasValidate for Protobuf<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -51,6 +51,13 @@ impl<T: Validate> HasValidate for Protobuf<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Protobuf<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
@@ -41,9 +41,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_extra::extract::Query;
|
use axum_extra::extract::Query;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Query<T> {
|
impl<T: Validate> HasValidate for Query<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -52,6 +52,13 @@ impl<T: Validate> HasValidate for Query<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Query<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
@@ -49,16 +49,14 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::Valid;
|
use crate::{Valid, ValidArgs};
|
||||||
use axum_extra::routing::TypedPath;
|
use axum_extra::routing::TypedPath;
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::Display;
|
||||||
|
|
||||||
impl<T: Display> Display for Valid<T> {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
self.0.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: TypedPath + Display> TypedPath for Valid<T> {
|
impl<T: TypedPath + Display> TypedPath for Valid<T> {
|
||||||
const PATH: &'static str = T::PATH;
|
const PATH: &'static str = T::PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: TypedPath + Display> TypedPath for ValidArgs<T> {
|
||||||
|
const PATH: &'static str = T::PATH;
|
||||||
|
}
|
||||||
|
|||||||
11
src/form.rs
11
src/form.rs
@@ -38,9 +38,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum::Form;
|
use axum::Form;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Form<T> {
|
impl<T: Validate> HasValidate for Form<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -49,6 +49,13 @@ impl<T: Validate> HasValidate for Form<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Form<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
11
src/json.rs
11
src/json.rs
@@ -38,9 +38,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum::Json;
|
use axum::Json;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Json<T> {
|
impl<T: Validate> HasValidate for Json<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -49,6 +49,13 @@ impl<T: Validate> HasValidate for Json<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Json<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
12
src/lib.rs
12
src/lib.rs
@@ -66,6 +66,12 @@ impl<E> DerefMut for Valid<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Display> Display for ValidArgs<T> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E> Valid<E> {
|
impl<E> Valid<E> {
|
||||||
/// Consume the `Valid` extractor and returns the inner type.
|
/// Consume the `Valid` extractor and returns the inner type.
|
||||||
pub fn into_inner(self) -> E {
|
pub fn into_inner(self) -> E {
|
||||||
@@ -101,6 +107,12 @@ impl<E> DerefMut for ValidArgs<E> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Display> Display for Valid<T> {
|
||||||
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
|
self.0.fmt(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<E> ValidArgs<E> {
|
impl<E> ValidArgs<E> {
|
||||||
/// Consume the `ValidArgs` extractor and returns the inner type.
|
/// Consume the `ValidArgs` extractor and returns the inner type.
|
||||||
pub fn into_inner(self) -> E {
|
pub fn into_inner(self) -> E {
|
||||||
|
|||||||
@@ -47,9 +47,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_msgpack::{MsgPack, MsgPackRaw};
|
use axum_msgpack::{MsgPack, MsgPackRaw};
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for MsgPack<T> {
|
impl<T: Validate> HasValidate for MsgPack<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -58,6 +58,13 @@ impl<T: Validate> HasValidate for MsgPack<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for MsgPack<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for MsgPackRaw<T> {
|
impl<T: Validate> HasValidate for MsgPackRaw<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
fn get_validate(&self) -> &T {
|
fn get_validate(&self) -> &T {
|
||||||
@@ -65,6 +72,13 @@ impl<T: Validate> HasValidate for MsgPackRaw<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for MsgPackRaw<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
11
src/path.rs
11
src/path.rs
@@ -37,9 +37,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum::extract::Path;
|
use axum::extract::Path;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Path<T> {
|
impl<T: Validate> HasValidate for Path<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -47,3 +47,10 @@ impl<T: Validate> HasValidate for Path<T> {
|
|||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Path<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
11
src/query.rs
11
src/query.rs
@@ -41,9 +41,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum::extract::Query;
|
use axum::extract::Query;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Query<T> {
|
impl<T: Validate> HasValidate for Query<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -52,6 +52,13 @@ impl<T: Validate> HasValidate for Query<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Query<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
@@ -61,9 +61,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum::TypedHeader;
|
use axum::TypedHeader;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for TypedHeader<T> {
|
impl<T: Validate> HasValidate for TypedHeader<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -72,6 +72,13 @@ impl<T: Validate> HasValidate for TypedHeader<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for TypedHeader<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
@@ -50,9 +50,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_typed_multipart::{BaseMultipart, TypedMultipart};
|
use axum_typed_multipart::{BaseMultipart, TypedMultipart};
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate, R> HasValidate for BaseMultipart<T, R> {
|
impl<T: Validate, R> HasValidate for BaseMultipart<T, R> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -61,6 +61,13 @@ impl<T: Validate, R> HasValidate for BaseMultipart<T, R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>, R> HasValidateArgs<'v> for BaseMultipart<T, R> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for TypedMultipart<T> {
|
impl<T: Validate> HasValidate for TypedMultipart<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
fn get_validate(&self) -> &T {
|
fn get_validate(&self) -> &T {
|
||||||
@@ -68,6 +75,13 @@ impl<T: Validate> HasValidate for TypedMultipart<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for TypedMultipart<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
11
src/yaml.rs
11
src/yaml.rs
@@ -42,9 +42,9 @@
|
|||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::HasValidate;
|
use crate::{HasValidate, HasValidateArgs};
|
||||||
use axum_yaml::Yaml;
|
use axum_yaml::Yaml;
|
||||||
use validator::Validate;
|
use validator::{Validate, ValidateArgs};
|
||||||
|
|
||||||
impl<T: Validate> HasValidate for Yaml<T> {
|
impl<T: Validate> HasValidate for Yaml<T> {
|
||||||
type Validate = T;
|
type Validate = T;
|
||||||
@@ -53,6 +53,13 @@ impl<T: Validate> HasValidate for Yaml<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'v, T: ValidateArgs<'v>> HasValidateArgs<'v> for Yaml<T> {
|
||||||
|
type ValidateArgs = T;
|
||||||
|
fn get_validate_args(&self) -> &Self::ValidateArgs {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{ValidTest, ValidTestParameter};
|
use crate::tests::{ValidTest, ValidTestParameter};
|
||||||
|
|||||||
Reference in New Issue
Block a user