diff --git a/Cargo.toml b/Cargo.toml index b40e08f..c5eca8c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axum-valid" -version = "0.1.0" +version = "0.2.0" description = "Validator for axum" authors = ["GengTeng "] license = "MIT" @@ -23,5 +23,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axum = "0.6.18" -validator = "0.16.0" +axum = "0.6" +validator = "0.16" diff --git a/src/lib.rs b/src/lib.rs index 92658f1..75f9a1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,40 +55,40 @@ impl From for ValidRejection { } } -pub trait Inner0 { - type Inner: Validate; +pub trait HasValidate { + type Validate: Validate; type Rejection; - fn inner0_ref(&self) -> &Self::Inner; + fn get_validate(&self) -> &Self::Validate; } -impl Inner0 for Json { - type Inner = T; +impl HasValidate for Json { + type Validate = T; type Rejection = JsonRejection; - fn inner0_ref(&self) -> &T { + fn get_validate(&self) -> &T { &self.0 } } -impl Inner0 for Form { - type Inner = T; +impl HasValidate for Form { + type Validate = T; type Rejection = FormRejection; - fn inner0_ref(&self) -> &T { + fn get_validate(&self) -> &T { &self.0 } } -impl Inner0 for Query { - type Inner = T; +impl HasValidate for Query { + type Validate = T; type Rejection = QueryRejection; - fn inner0_ref(&self) -> &T { + fn get_validate(&self) -> &T { &self.0 } } -impl Inner0 for Path { - type Inner = T; +impl HasValidate for Path { + type Validate = T; type Rejection = QueryRejection; - fn inner0_ref(&self) -> &T { + fn get_validate(&self) -> &T { &self.0 } } @@ -98,16 +98,16 @@ impl FromRequest for Valid where S: Send + Sync + 'static, B: Send + Sync + 'static, - T: Inner0 + FromRequest, - T::Inner: Validate, - ::Rejection: IntoResponse, - ValidRejection<::Rejection>: From<>::Rejection>, + T: HasValidate + FromRequest, + T::Validate: Validate, + ::Rejection: IntoResponse, + ValidRejection<::Rejection>: From<>::Rejection>, { - type Rejection = ValidRejection<::Rejection>; + type Rejection = ValidRejection<::Rejection>; async fn from_request(req: Request, state: &S) -> Result { let valid = T::from_request(req, state).await?; - valid.inner0_ref().validate()?; + valid.get_validate().validate()?; Ok(Valid(valid)) } } @@ -116,16 +116,16 @@ where impl FromRequestParts for Valid where S: Send + Sync + 'static, - T: Inner0 + FromRequestParts, - T::Inner: Validate, - ::Rejection: IntoResponse, - ValidRejection<::Rejection>: From<>::Rejection>, + T: HasValidate + FromRequestParts, + T::Validate: Validate, + ::Rejection: IntoResponse, + ValidRejection<::Rejection>: From<>::Rejection>, { - type Rejection = ValidRejection<::Rejection>; + type Rejection = ValidRejection<::Rejection>; async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { let valid = T::from_request_parts(parts, state).await?; - valid.inner0_ref().validate()?; + valid.get_validate().validate()?; Ok(Valid(valid)) } }