Why this fires¶
An enum variant's discriminant value doesn't fit inside the enum's declared backing type. enum E: u8 limits every discriminant to the 0..=255 range; a value outside that range can't round-trip through to_int()/from_int() on that backing type.
enum E: u8 { X = 300 }
// ^^^^^^^ error[TE115]: discriminant 300 for `E::X` does not fit backing type `u8` (0..=255)Fix it¶
1. Use a value that fits¶
enum E: u8 { X = 200 } // ok — within 0..=2552. Widen the backing type¶
enum E: u16 { X = 300 } // ok — u16 covers 0..=65535See also¶
TE114— numeric discriminants require a non-generic, all-unit enum.TE116— duplicate discriminant value.- /docs/data-structures#enums — numeric enum discriminants and backing types.