add support for validify

This commit is contained in:
gengteng
2023-10-19 23:12:32 +08:00
parent 61bf3c5b23
commit b2d2c3d7ca
14 changed files with 1139 additions and 354 deletions

View File

@@ -114,6 +114,24 @@ impl<T: validify::Modify> crate::HasModify for Form<T> {
}
}
#[cfg(feature = "validify")]
impl<T> crate::PayloadExtractor for Form<T> {
type Payload = T;
fn get_payload(self) -> Self::Payload {
self.0
}
}
#[cfg(feature = "validify")]
impl<T: validify::Validify> crate::HasValidify for Form<T> {
type Validify = T;
type PayloadExtractor = Form<T::Payload>;
fn from_validified(v: Self::Validify) -> Self {
Form(v)
}
}
#[cfg(test)]
mod tests {
use crate::tests::{ValidTest, ValidTestParameter};

View File

@@ -114,6 +114,25 @@ impl<T: validify::Modify> crate::HasModify for Query<T> {
}
}
#[cfg(feature = "validify")]
impl<T> crate::PayloadExtractor for Query<T> {
type Payload = T;
fn get_payload(self) -> Self::Payload {
self.0
}
}
#[cfg(feature = "validify")]
impl<T: validify::Validify> crate::HasValidify for Query<T> {
type Validify = T;
type PayloadExtractor = Query<T::Payload>;
fn from_validified(v: Self::Validify) -> Self {
Query(v)
}
}
#[cfg(test)]
mod tests {
use crate::tests::{ValidTest, ValidTestParameter};

View File

@@ -97,10 +97,10 @@
#[cfg(feature = "garde")]
use crate::Garde;
#[cfg(feature = "validify")]
use crate::{Modified, Validated, ValidifiedByRef};
#[cfg(feature = "validator")]
use crate::{Valid, ValidEx};
#[cfg(feature = "validify")]
use crate::{Validated, Validified};
#[cfg(any(feature = "validator", feature = "garde", feature = "validify"))]
use axum_extra::routing::TypedPath;
#[cfg(any(feature = "validator", feature = "garde", feature = "validify"))]
@@ -127,6 +127,11 @@ impl<T: TypedPath + Display> TypedPath for Validated<T> {
}
#[cfg(feature = "validify")]
impl<T: TypedPath + Display> TypedPath for Validified<T> {
impl<T: TypedPath + Display> TypedPath for Modified<T> {
const PATH: &'static str = T::PATH;
}
#[cfg(feature = "validify")]
impl<T: TypedPath + Display> TypedPath for ValidifiedByRef<T> {
const PATH: &'static str = T::PATH;
}