diff --git a/README.md b/README.md index ca5d828..b51fddb 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ This crate provides a `Valid` type that can be used in combination with `Json`, `Path`, `Query`, and `Form` extractors to validate the entities that implement the `Validate` trait from the `validator` crate. +It also provides a `ValidEx` type that works similarly to `Valid`, but can perform validation requiring additional arguments by using types that implement the `ValidateArgs` trait. + Additional extractors like `TypedHeader`, `MsgPack`, `Yaml` etc. are supported through optional features. The full list of supported extractors is in the Features section below. ## Basic usage diff --git a/src/extra/typed_path.rs b/src/extra/typed_path.rs index 84d95a4..6704c22 100644 --- a/src/extra/typed_path.rs +++ b/src/extra/typed_path.rs @@ -49,7 +49,7 @@ //! } //! ``` -use crate::{Valid, ValidArgs}; +use crate::{Valid, ValidEx}; use axum_extra::routing::TypedPath; use std::fmt::Display; @@ -57,6 +57,6 @@ impl TypedPath for Valid { const PATH: &'static str = T::PATH; } -impl TypedPath for ValidArgs { +impl TypedPath for ValidEx { const PATH: &'static str = T::PATH; } diff --git a/src/lib.rs b/src/lib.rs index 8e91ab5..5076929 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,7 @@ impl DerefMut for Valid { } } -impl Display for ValidArgs { +impl Display for ValidEx { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } @@ -79,9 +79,11 @@ impl Valid { } } -/// `ValidArgs` can be used with extractors from the various modules. +/// # `ValidEx` data extractor +/// +/// `ValidEx` can be used with extractors from the various modules. /// Refer to the examples for `Valid` in each module - the usage of -/// `ValidArgs` is similar, except the inner data type implements +/// `ValidEx` is similar, except the inner data type implements /// `ValidateArgs` instead of `Validate`. /// /// `ValidateArgs` is usually automatically implemented by validator's @@ -89,11 +91,11 @@ impl Valid { /// /// Note that the documentation for each module currently only shows /// examples of `Valid`, and does not demonstrate concrete usage of -/// `ValidArgs`, but the usage is analogous. +/// `ValidEx`, but the usage is analogous. #[derive(Debug, Clone, Copy, Default)] -pub struct ValidArgs(pub E); +pub struct ValidEx(pub E); -impl Deref for ValidArgs { +impl Deref for ValidEx { type Target = E; fn deref(&self) -> &Self::Target { @@ -101,7 +103,7 @@ impl Deref for ValidArgs { } } -impl DerefMut for ValidArgs { +impl DerefMut for ValidEx { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } @@ -113,8 +115,8 @@ impl Display for Valid { } } -impl ValidArgs { - /// Consume the `ValidArgs` extractor and returns the inner type. +impl ValidEx { + /// Consume the `ValidEx` extractor and returns the inner type. pub fn into_inner(self) -> E { self.0 } @@ -375,7 +377,7 @@ where } #[async_trait] -impl<'v, S, B, E> FromRequest for ValidArgs +impl<'v, S, B, E> FromRequest for ValidEx where S: Send + Sync, B: Send + Sync + 'static, @@ -402,12 +404,12 @@ where error: ValidError::Valid(e), response_builder: context.response_builder, })?; - Ok(ValidArgs(inner)) + Ok(ValidEx(inner)) } } #[async_trait] -impl<'v, S, E> FromRequestParts for ValidArgs +impl<'v, S, E> FromRequestParts for ValidEx where S: Send + Sync, E: HasValidateArgs<'v> + FromRequestParts, @@ -433,7 +435,7 @@ where error: ValidError::Valid(e), response_builder: context.response_builder, })?; - Ok(ValidArgs(inner)) + Ok(ValidEx(inner)) } }