Support Private Enum Variants
Nobody has claimed this yet.
- Dominant language
- Markdown
- Stars
- 6.6k
- Forks
- 1.7k
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Description
There should be a way to mark enum variants as private.
Possible syntax:
enum MyThing {
priv OneState(Foo),
priv OtherState(Bar),
}
Motivation
Type authors should be able to use an enum to represent their type without exposing that to users. Today if a type is an enum that is visible to users so almost any change is a breaking change (I think only adding an additional private field to a struct-style variant is not breaking).
For example if the leading example was written today without priv a user would be able to do:
match v {
MyThing::OneState(..) => true,
MyThing::OtherState(..) => false,
};
Possible Alternatives
#[doc(hidden)]
enum MyThing {
#[doc(hidden)] OneState(Foo),
#[doc(hidden)] OtherState(Bar),
}
This hides it from documentation but doesn't actually protect against using it. It is possible that the user copies an old code sample, guesses a name without knowing it is private or an IDE autocompletes it and the user will unknowingly be relying on a (logically) private API.
Internal Enum
enum MyThingImpl {
OneState(Foo),
OtherState(Bar),
}
pub struct MyThing(MyThingImpl);
This works but results in tedious code. Internals must be accessed as self.0 and if you want to derive traits this needs to be done on both the wrapper and the impl.
Related: https://github.com/rust-lang/rfcs/pull/2028 https://github.com/rust-lang/rust/issues/32770
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files, tests, or implementation entry points. Start by reviewing the proposed syntax, motivation, alternatives, and related RFC links; done would require an agreed design for private enum variants rather than only documentation hiding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100