update to 0.5.0
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user