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

Significant

Has two strings - one for meaning, other for long description

Tuple Fields of Significant

0: &'a str1: &'a str
Reserved

Reserved bit (flag) may has different types of reservation. Ex: OEM and Future using

Tuple Fields of Reserved

0: &'a str
ShouldBe0

Should always be set

ShouldBe1

Should always be unset

Unknown

Unknown for current specification

Undefined

Undefined in current specification

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

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.