Do you ever wish for enum subtypes?
I'm prototyping a programming language and considering what features I want to support for union types / enums there. One sentiment I've heard about Rust several times is how nice it would be to be able to "subtype" enums - I think there are even some RFCs or pre-RFCs that try to tackle this. Specifically, given a enum like
enum MyLibraryError {
InvariantViolation(String),
OutOfMemory,
UnknownError
}
You would be able to define its "subtype" like this:
enum KnownErrors = MyLibraryError::{InvariantViolation, OutOfMemory}
My question to y'all: do you ever wish for such a feature? What are the practical problems it would help you solve?
I'd appreciate any thoughts!