Trait datatypes::ImportantEnumTrait

source ·
pub trait ImportantEnumTrait: Sized {
    // Required method
    fn new(data: u64) -> Result<Self>;
}
Expand description

This trait is implemented by enums to be used in the artificial Enum struct

Required Methods§

source

fn new(data: u64) -> Result<Self>

This function creates a new instance of Self where data is the offset of the Option

§Arguments

data - id of the version

§example
enum Example {
    A,
    B
}
impl datatypes::ImportantEnumTrait for Example {
    fn new(data: u64) -> binary_utils::Result<Self> {
        match data {
            0 => Ok(Self::A),
            1 => Ok(Self::B),
            _ => Err(binary_utils::Error::InvalidId),
        }
    }
}
#[test]
fn test() {
    let a = Example::new(0);
    assert!(a, Ok(Example::A));
    let b = Example::new(2);
    assert!(b, Err(Error::InvalidId));
}

Object Safety§

This trait is not object safe.

Implementors§