impl HasValidateArgs for all extractors
This commit is contained in:
@@ -38,9 +38,9 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use crate::HasValidate;
|
||||
use crate::{HasValidate, HasValidateArgs};
|
||||
use axum_extra::extract::Form;
|
||||
use validator::Validate;
|
||||
use validator::{Validate, ValidateArgs};
|
||||
|
||||
impl<T: Validate> HasValidate for Form<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)]
|
||||
mod tests {
|
||||
use crate::tests::{ValidTest, ValidTestParameter};
|
||||
|
||||
@@ -40,9 +40,9 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use crate::HasValidate;
|
||||
use crate::{HasValidate, HasValidateArgs};
|
||||
use axum_extra::protobuf::Protobuf;
|
||||
use validator::Validate;
|
||||
use validator::{Validate, ValidateArgs};
|
||||
|
||||
impl<T: Validate> HasValidate for Protobuf<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)]
|
||||
mod tests {
|
||||
use crate::tests::{ValidTest, ValidTestParameter};
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use crate::HasValidate;
|
||||
use crate::{HasValidate, HasValidateArgs};
|
||||
use axum_extra::extract::Query;
|
||||
use validator::Validate;
|
||||
use validator::{Validate, ValidateArgs};
|
||||
|
||||
impl<T: Validate> HasValidate for Query<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)]
|
||||
mod tests {
|
||||
use crate::tests::{ValidTest, ValidTestParameter};
|
||||
|
||||
@@ -49,16 +49,14 @@
|
||||
//! }
|
||||
//! ```
|
||||
|
||||
use crate::Valid;
|
||||
use crate::{Valid, ValidArgs};
|
||||
use axum_extra::routing::TypedPath;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
impl<T: Display> Display for Valid<T> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
use std::fmt::Display;
|
||||
|
||||
impl<T: TypedPath + Display> TypedPath for Valid<T> {
|
||||
const PATH: &'static str = T::PATH;
|
||||
}
|
||||
|
||||
impl<T: TypedPath + Display> TypedPath for ValidArgs<T> {
|
||||
const PATH: &'static str = T::PATH;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user