#[non_exhaustive]pub struct ChoiceDef {
pub name: String,
pub endian: Endian,
pub arms: Vec<Arm>,
pub other: Option<String>,
pub other_bytes: Option<usize>,
pub doc: Option<String>,
pub derives: Vec<Derive>,
}Expand description
The arms of a Segment::Switch.
With a fallback other variant, an unmatched value keeps its bytes: the rest of
the body, or other_bytes of them.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringThe type name.
endian: EndianByte order of the arms’ fields.
arms: Vec<Arm>The arms, in declaration order.
other: Option<String>The fallback variant for an unmatched value. None makes it a decode error.
other_bytes: Option<usize>The fallback’s size in bytes, when the choice is a union.
None takes the rest of the body, so no field can follow the switch.
doc: Option<String>Documentation.
derives: Vec<Derive>Derives for this choice, written after the module’s.
Implementations§
Source§impl ChoiceDef
impl ChoiceDef
Sourcepub fn with_derives(self, derives: Vec<Derive>) -> Self
pub fn with_derives(self, derives: Vec<Derive>) -> Self
Sets the derives written on this choice, after the module’s.
Sourcepub fn with_endian(self, endian: Endian) -> Self
pub fn with_endian(self, endian: Endian) -> Self
Sets the byte order.
Sourcepub fn with_other(self, other: &str) -> Self
pub fn with_other(self, other: &str) -> Self
Adds a fallback variant that keeps an unmatched value’s bytes.
Sourcepub fn with_other_bytes(self, bytes: usize) -> Self
pub fn with_other_bytes(self, bytes: usize) -> Self
Makes the choice a union of bytes bytes.
Every arm must fill exactly that size, and a field can follow the switch.
Sourcepub fn open_ended(&self) -> bool
pub fn open_ended(&self) -> bool
Whether the choice reads to the end of the body.
True when any arm does, or when the fallback has no fixed size.