oxidecomputer / idolatry

An experimental IPC interface definition language for Hubris.
Mozilla Public License 2.0
17 stars 11 forks source link

Supporting `Option` for enums #17

Open mkeeter opened 2 years ago

mkeeter commented 2 years ago

It would be nice to support Option<T> where T is a simple enum type.

This isn't supported by either ssmarshal or zerocopy. I think we'd want to implement a special zerocopy case like we're doing for bool already. It turns out that the compiler is smart enough to pack None into an unused enum slot, which you can find using

    let a: Option<TofinoSeqError> = None;
    let a: u8 = unsafe { std::mem::transmute(a) };

so we could use this value for the None case.