gengteng ba3b23a419 update
2023-06-06 13:53:47 +08:00
2023-06-06 13:53:47 +08:00
2023-06-06 09:45:14 +08:00
2023-06-06 13:53:47 +08:00
2023-06-06 13:45:20 +08:00

axum-valid

This crate provides a Valid type that can be used in combination with Json, Path, Query, and Form types to validate the entities that implement the Validate trait.

Usage

use validator::Validate;
use serde::Deserialize;

#[derive(Debug, Validate, Deserialize)]
pub struct Pager {
    #[validate(range(min = 1, max = 50))]
    pub page_size: usize,
    #[validate(range(min = 1))]
    pub page_no: usize,
}

pub async fn get_page_by_query(
    Valid(Query(pager)): Valid<Query<Pager>>,
) {
    assert!((1..=50).contains(&pager.page_size));
    assert!((1..).contains(&pager.page_no));
}

pub async fn get_page_by_json(
    Valid(Json(pager)): Valid<Json<Pager>>,
) {
    assert!((1..=50).contains(&pager.page_size));
    assert!((1..).contains(&pager.page_no));
}
Description
No description provided
Readme 246 KiB
Languages
Rust 100%