I’m using an enum to store information about a region of memory. The enum has 5 variants, and has #[repr(u8)]. Since it’s possible for memory corruption to invalidate an enum such that it holds an invalid tag, I want to be able to detect this with a _ => {} clause in a match. The compiler complains about this being an unreachable pattern however, since I’m matching on all other variants.
Is there an attribute that allows me to avoid this? If not, I think this should be considered in the language’s design.
Rust enums are not allowed to contain unspecified values (although, I guess with the repr attribute most of the optimizations that would break it are disabled). I think you should use a transparent newtype for these sorts of scenarios, it gives you much more direct control while being almost as ergonomic: