Enum bitfield_layout::layouts::FlagType [−][src]
pub enum FlagType<'a> { Significant(&'a str, &'a str), Reserved(&'a str), ShouldBe0, ShouldBe1, Unknown, Undefined, }
Expand description
Complex enumeration for several types of bit (flag)
This enum variants may be used to show difference beetween meaningful and reserved flags.
// Bitfield type definition struct Light(u8); impl Light { const LAYOUT: [FlagType<'static>; 8] = [ FlagType::Significant("Red", "Red is the color at the long wavelength end"), FlagType::Significant("Blue", "Blue is one of the three primary colours of pigments"), FlagType::Significant("Green", "Green is the color between blue and yellow"), FlagType::Reserved("Invisible"), FlagType::ShouldBe0, FlagType::ShouldBe1, FlagType::Unknown, FlagType::Undefined, ]; } // Implementation impl Layout for Light { type Layout = slice::Iter<'static, FlagType<'static>>; fn layout() -> Self::Layout { Light::LAYOUT.iter() } } impl BitFieldLayout for Light { type Value = u8; fn get(&self) -> Self::Value { self.0 } fn set(&mut self, new: Self::Value) { self.0 = new; } } // Value assignment let white = Light(0b00100111); let result = white.flags() .enumerate() .find(|(n, f)| n == &5 && f.is_set == true) .map(|(_, f)| *f.value); let sample = Some(FlagType::ShouldBe1); assert_eq!(sample, result);
Variants
Has two strings - one for meaning, other for long description
Reserved bit (flag) may has different types of reservation. Ex: OEM and Future using
Tuple Fields of Reserved
0: &'a str
Should always be set
Should always be unset
Unknown for current specification
Undefined in current specification
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl<'a> RefUnwindSafe for FlagType<'a>
impl<'a> UnwindSafe for FlagType<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more