-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve values for unknown enum variants (#2008)
The `enum_number!` macro now takes the whole enum definition and generates `From` trait implementations to convert a value to the enum and back. The implementations can then be picked up by `serde` with `#[serde(from = "u8", into = "u8")]` to (de)serialize the types. ``` enum_number! { #[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[serde(from = "u8", into = "u8")] pub enum Foo { A = 1, B = 2, _ => Unknown(u8), } } ``` BREAKING CHANGE: The `Unknown` variant now takes the unknown value and the removed `fn num() -> u64` method can be replaced with `let v = u8::from(kind)`.
- Loading branch information
Showing
18 changed files
with
575 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.