pub trait ScpiEnumwhere
Self: Sized,{
// Required methods
fn from_mnemonic(s: &[u8]) -> Option<Self>;
fn mnemonic(&self) -> &'static [u8];
// Provided method
fn short_form(&self) -> &'static [u8] { ... }
}
Expand description
Common trait for getting an enum variant fom its MNEMonic
and back.
Usually derived by scpi_derive::ScpiEnum like below:
#[derive(Copy, Clone, PartialEq, Debug, scpi_derive::ScpiEnum)]
enum MyEnum {
#[scpi(mnemonic = b"BINary")]
Binary,
#[scpi(mnemonic = b"REAL")]
Real,
#[scpi(mnemonic = b"ASCii")]
Ascii,
#[scpi(mnemonic = b"L125")]
L125,
}
assert_eq!(MyEnum::from_mnemonic(b"real"), Some(MyEnum::Real));
assert_eq!(MyEnum::Binary.short_form(), b"BIN");
Required Methods§
sourcefn from_mnemonic(s: &[u8]) -> Option<Self>
fn from_mnemonic(s: &[u8]) -> Option<Self>
Get the enum variant from a mnemonic. Returns None if no variant matches the given mnemonic.
Provided Methods§
sourcefn short_form(&self) -> &'static [u8]
fn short_form(&self) -> &'static [u8]
Get the mnemonic short form
Example: ‘MNEMonic’ would return ‘MNEM’