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>

source

pub fn get_name(&self) -> Option<String>

Returns the optional identifier for this switch.

source

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.

source

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.

source

pub fn get_case(&self, index: usize) -> Option<&'dc SwitchCase<'_>>

Returns case reference from given index wrapped in an Option.

source

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.

source

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.

source

pub fn apply_switch(&self, _value: Vec<u8>, _length: usize)

Trait Implementations§

source§

impl<'dc> Debug for DCSwitch<'dc>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'dc> Display for DCSwitch<'dc>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'dc> From<DCSwitch> for DCSwitch<'dc>

source§

fn from(value: DCSwitch) -> Self

Converts to this type from the input type.
source§

impl<'dc> LegacyDCHash for DCSwitch<'dc>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.