pub struct Opt<T>(pub T);
Expand description

Rule to apply another rule to inner value of an Option

In case of a None value, it just return Ok(())

Example

use type_rules::prelude::*;

#[derive(Validator)]
struct Parameters {
    #[rule(Opt(MinMaxRange(1, 4)))]
    optional_parameter: Option<u32>,
}

let param = Parameters { optional_parameter: Some(1) };
assert!(param.check_validity().is_ok());

let param = Parameters { optional_parameter: None };
assert!(param.check_validity().is_ok());

let param = Parameters { optional_parameter: Some(5) };
assert!(param.check_validity().is_err());

Tuple Fields

0: T

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.