Skip to content

Commit

Permalink
Doc for externally-tagged enums
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Sep 15, 2024
1 parent 8021fb8 commit ae37e20
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions merde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,39 @@ macro_rules! impl_trait {
/// r#""foobar""#
/// );
/// ```
///
/// Externally tagged enums are also supported. For both owned and lifetimed variants:
///
/// ```rust
/// enum MyEnum {
/// Variant1(String),
/// Variant2(i32),
/// }
///
/// merde::derive! {
/// impl (JsonSerialize, ValueDeserialize) for enum MyEnum
/// externally_tagged {
/// "variant1" => Variant1,
/// "variant2" => Variant2,
/// }
/// }
///
/// enum MyLifetimedEnum<'a> {
/// Variant1(merde::CowStr<'a>),
/// Variant2(i32),
/// }
///
/// merde::derive! {
/// impl (JsonSerialize, ValueDeserialize) for enum MyLifetimedEnum<'a>
/// externally_tagged {
/// "variant1" => Variant1,
/// "variant2" => Variant2,
/// }
/// }
/// ```
///
/// This will serialize `MyEnum::Variant1("hello".into())` as `{"variant1":"hello"}`,
/// and `MyEnum::Variant2(42)` as `{"variant2":42}`.
#[macro_export]
macro_rules! derive {
// owned tuple structs (transparent)
Expand Down

0 comments on commit ae37e20

Please sign in to comment.