pub trait ValidateMinimum<T>where
    T: PartialOrd + PartialEq,
{ fn validate_minimum(&self, minimum: T) -> Result<(), MinimumError>; }
Expand description

Minimum validation of the number.

See https://json-schema.org/understanding-json-schema/reference/numeric.html#range

use serde_json::json;
use serde_valid::{Validate, ValidateMinimum};
struct MyType(i32);

impl ValidateMinimum<i32> for MyType {
    fn validate_minimum(&self, minimum: i32) -> Result<(), serde_valid::MinimumError> {
        self.0.validate_minimum(minimum)
    }
}

#[derive(Validate)]
struct TestStruct {
    #[validate(minimum = 5)]
    val: MyType,
}

let s = TestStruct { val: MyType(3) };

assert_eq!(
    s.validate().unwrap_err().to_string(),
    json!({
        "errors": [],
        "properties": {
            "val": {
                "errors": ["The number must be `>= 5`."]
            }
        }
    })
    .to_string()
);

Required Methods

Implementations on Foreign Types

Implementors