casey / casey/x-serialization-format
Enum Evolution
- Dominant language
- Rust
- Stars
- 1
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
It seems highly desirable to allow adding and removing enum variants in a backwards compatible way.
There are two ways to support this:
1. Unknown variant: Enums may optionally have a unit variant marked `#[data(unknown)]`. When a decoder encounters an unknown variant, it returns that variant.
```rust
#[derive(Data)]
enum Foo {
Bar,
#[data(unknown)]
Unknown
}
```
2. Enum decoding always returns `Option`: Functions that decode enums always have the signature `fn load(...) -> Option`. If the decoder encounters an unknown variant, it returns `None`.
The downside of 1. is that you'll have to match against and handle the `Unknown` variant. The downside of 2. is that a double-option would be required to indicate a value not being present: `fn load(...) -> Option>`. The outer option is `None` if the enum isn't present, and the inner option is `None` if an unknown variant was encountered.
Contributor guide
No contributing guide indexed for this repository
Research direction
Review the existing enum decoding and load APIs, then compare the proposed #[data(unknown)] variant with Option-based decoding. Done means the project has selected and implemented a backwards-compatible behavior for unknown enum variants, including how absent values are represented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100