Compare enum with number with no_std


pub enum MessageId {
    Serial = 100,
    Firmware = 101,

let i: u32 = 100;
match i {
  MessageId::Serial => {}
  MessageId::Firmware => {}

I would to do it using the enum-primitive-derive + num-traits, but i build for embedded so have no an std.
Is it able to compare enum with number?

If you disable the std feature from num-traits (it's enabled by default), you should be able to derive FromPrimitive/ToPrimitive and convert a u32 to a MessageId like normal.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.