fn check_bound<T>(
    property_name: &PropertyName,
    value: T,
    bound: &Option<String>,
    check_out_of_bound: fn(T, T) -> bool,
) -> ValidationResult<T>
where
    T: FromStr + std::cmp::PartialOrd + Display + Copy,
{
    if let Some(bound) = bound {
        let bound: T = parse::<T>(property_name, bound.as_str())?;
        if check_out_of_bound(value, bound) {
            return Err(Error::PropertyValueOutOfBounds {
                property_name: property_name.clone(),
                received: value.to_string(),
                expected: bound.to_string(),
            });
        }
    }

    Ok(value)
}
/// Check if a value is inside a certain bound
///
/// # Arguments
///
/// * `property_name` - name of the property
/// * `value` - value to be validated
/// * `bound` - upper/lower bound
/// * `check_out_of_bound` - the method to check against the bound
///
Check if a value is inside a certain bound
Check if a value is inside a certain bound
fn check_bound<T>(
    property_name: &PropertyName,
    value: T,
    bound: &Option<String>,
    check_out_of_bound: fn(T, T) -> bool,
) -> ValidationResult<T>
where
    T: FromStr + std::cmp::PartialOrd + Display + Copy,
{
    if let Some(bound) = bound {
        let bound: T = parse::<T>(property_name, bound.as_str())?;
        if check_out_of_bound(value, bound) {
            return Err(Error::PropertyValueOutOfBounds {
                property_name: property_name.clone(),
                received: value.to_string(),
                expected: bound.to_string(),
            });
        }
    }
    Ok(value)
}
fn check_bound < T > ( property_name : & PropertyName , value : T , bound : & Option < String > , check_out_of_bound : fn ( T , T ) -> bool , ) -> ValidationResult < T > where T : FromStr + std :: cmp :: PartialOrd + Display + Copy , { if let Some ( bound ) = bound { let bound : T = parse :: < T > ( property_name , bound . as_str ( ) ) ? ; if check_out_of_bound ( value , bound ) { return Err ( Error :: PropertyValueOutOfBounds { property_name : property_name . clone ( ) , received : value . to_string ( ) , expected : bound . to_string ( ) , } ) ; } } Ok ( value ) }
Check if a value is inside a certain bound
Check if a value is inside a certain bound
property_name
&PropertyName
value
T
bound
&Option<String>
check_out_of_bound
fn(T, T) -> bool