update to 0.5.0

This commit is contained in:
gengteng
2023-08-04 18:50:02 +08:00
parent f3f0171e72
commit d95e04b4d4
19 changed files with 836 additions and 292 deletions

View File

@@ -6,14 +6,12 @@ use axum::http::request::Parts;
use axum::response::{IntoResponse, Response};
use axum::routing::get;
use axum::Router;
use axum_valid::{HasValidate, Valid, ValidRejection, VALIDATION_ERROR_STATUS};
use axum_valid::{HasValidate, Valid, VALIDATION_ERROR_STATUS};
use hyper::StatusCode;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use validator::Validate;
mod utils;
const MY_DATA_HEADER: &str = "My-Data";
// 1. Implement your own extractor.
@@ -66,20 +64,11 @@ where
// 2.1. Implement `HasValidate` for your extractor
impl HasValidate for MyData {
type Validate = Self;
type Rejection = MyDataRejection;
fn get_validate(&self) -> &Self::Validate {
self
}
}
// 2.2. Implement `From<MyDataRejection>` for `ValidRejection<MyDataRejection>`.
impl From<MyDataRejection> for ValidRejection<MyDataRejection> {
fn from(value: MyDataRejection) -> Self {
Self::Inner(value)
}
}
#[tokio::test]
async fn main() -> anyhow::Result<()> {
let router = Router::new().route("/", get(handler));
@@ -125,8 +114,8 @@ async fn main() -> anyhow::Result<()> {
.send()
.await?;
assert_eq!(invalid_my_data_response.status(), VALIDATION_ERROR_STATUS);
#[cfg(feature = "into_json")]
utils::check_json(invalid_my_data_response).await;
// #[cfg(feature = "into_json")]
// test::check_json(invalid_my_data_response).await;
println!("Valid<MyData> works.");
drop(server_guard);