Struct type_rules::rules::Opt
source · [−]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
impl<T> RefUnwindSafe for Opt<T> where
T: RefUnwindSafe,
impl<T> Send for Opt<T> where
T: Send,
impl<T> Sync for Opt<T> where
T: Sync,
impl<T> Unpin for Opt<T> where
T: Unpin,
impl<T> UnwindSafe for Opt<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more