kupiakos / open-enum

Opens up a Rust enum to allow for non-specified values
Apache License 2.0
8 stars 6 forks source link

Option to keep/generate "closed form" enum #25

Open fu5ha opened 3 days ago

fu5ha commented 3 days ago

In implementing #24 and using it in our code based, the TryFromKnownRepr is useful but only moderately, since you still can't get an exhaustive match on just the known variants afterwards. It would be nice to somehow expose the original closed form of the enum as well, either as just OriginalIdentClosed or perhaps some trait

trait OpenEnum {
    type Closed;
}

then you can OriginalIdent::Closed?

And provide infallible From<Closed> for Open and fallible TryFrom<Closed> for Open, as replacement for TryFromKnownRepr.

fu5ha commented 1 day ago

I took a stab at implementing this in this branch: https://github.com/EmbarkStudios/open-enum/tree/with_closed but in actually trying to use it in our FFI layer it proved less ergonomic than I thought, so I'm not going to go ahead with cleaning it up and PRing unless some more design work happens.