Trait scpi::option::ScpiEnum

source ·
pub trait ScpiEnum
where 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§

source

fn from_mnemonic(s: &[u8]) -> Option<Self>

Get the enum variant from a mnemonic. Returns None if no variant matches the given mnemonic.

source

fn mnemonic(&self) -> &'static [u8]

Return full MNEMonic of enum variant.

Provided Methods§

source

fn short_form(&self) -> &'static [u8]

Get the mnemonic short form

Example: ‘MNEMonic’ would return ‘MNEM’

Object Safety§

This trait is not object safe.

Implementors§