Struct donet_core::dcswitch::DCSwitch
source · pub struct DCSwitch<'dc> {
name: Option<String>,
key: DCField<'dc>,
cases: Vec<SwitchCase<'dc>>,
default_case: Option<SwitchCase<'dc>>,
case_fields: Vec<&'dc DCField<'dc>>,
cases_by_value: HashMap<Vec<u8>, usize>,
}
Expand description
Represents a DC Switch statement, which can appear inside a dclass declaration and represents two or more alternative unpacking schemes based on the first field read.
Fields§
§name: Option<String>
§key: DCField<'dc>
§cases: Vec<SwitchCase<'dc>>
§default_case: Option<SwitchCase<'dc>>
§case_fields: Vec<&'dc DCField<'dc>>
§cases_by_value: HashMap<Vec<u8>, usize>
Implementations§
source§impl<'dc> DCSwitch<'dc>
impl<'dc> DCSwitch<'dc>
sourcepub fn get_key_parameter(&self) -> &'dc DCField<'_>
pub fn get_key_parameter(&self) -> &'dc DCField<'_>
Returns the key parameter on which the switch is based.
The value of this parameter in the record determines which one of the several cases within the switch will be used.
sourcepub fn get_num_cases(&self) -> usize
pub fn get_num_cases(&self) -> usize
Returns the number of different cases within the switch.
The legal values for case_index range from 0 to n_cases - 1.
sourcepub fn get_case(&self, index: usize) -> Option<&'dc SwitchCase<'_>>
pub fn get_case(&self, index: usize) -> Option<&'dc SwitchCase<'_>>
Returns case reference from given index wrapped in an Option.
sourcepub fn get_default_case(&self) -> Option<&'dc SwitchCase<'_>>
pub fn get_default_case(&self) -> Option<&'dc SwitchCase<'_>>
Returns default case reference wrapped in an Option.
A default case is optional, so None
can be returned.
sourcepub fn get_case_index_by_value(&self, value: Vec<u8>) -> Option<usize>
pub fn get_case_index_by_value(&self, value: Vec<u8>) -> Option<usize>
Returns the index of the case with the given packed value.
None
is returned if no case with that value is found.
pub fn apply_switch(&self, _value: Vec<u8>, _length: usize)
Trait Implementations§
source§impl<'dc> LegacyDCHash for DCSwitch<'dc>
impl<'dc> LegacyDCHash for DCSwitch<'dc>
source§fn generate_hash(&self, hashgen: &mut DCHashGenerator)
fn generate_hash(&self, hashgen: &mut DCHashGenerator)
Accumulates the properties of this DC element into the file hash.
Auto Trait Implementations§
impl<'dc> Freeze for DCSwitch<'dc>
impl<'dc> RefUnwindSafe for DCSwitch<'dc>
impl<'dc> Send for DCSwitch<'dc>
impl<'dc> Sync for DCSwitch<'dc>
impl<'dc> Unpin for DCSwitch<'dc>
impl<'dc> UnwindSafe for DCSwitch<'dc>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more