[][src]Trait photonix::focus::GetOption

pub trait GetOption<Value> {
    fn get_option(self) -> Option<Value>;
}

Returns the target field of a container (enum) by value as an Option, consumes the container (unless it implements Copy).

Auto-derive creates the implementation for all fields in enum variants, works for enums (both with named and unnamed fields) if

  • all fields have concrete types,
  • all field types are different.

If you're using the derive macro, and the actual enum variant is different from the target variant, it returns None (see example).

Examples

 #[derive(Debug, GetOption, PartialEq)]
 pub enum Deviation {
     Signed(i32),
     Unsigned(u32),
 }

 let d = || Deviation::Signed(-10);

 let signed_value: Option<i32> = d().get_option();

 assert_eq!(Some(-10), signed_value);

 let unsigned_value: Option<u32> = d().get_option();

 assert_eq!(None, unsigned_value);

 let d2 = Deviation::Unsigned(10);

 let unsigned_value2: Option<u32> = d2.get_option();

 assert_eq!(Some(10), unsigned_value2);

Required methods

fn get_option(self) -> Option<Value>

Loading content...

Implementors

Loading content...