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