Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support embedding enums #19

Closed
ptrus opened this issue Sep 17, 2021 · 0 comments · Fixed by #20
Closed

Support embedding enums #19

ptrus opened this issue Sep 17, 2021 · 0 comments · Fixed by #20
Assignees

Comments

@ptrus
Copy link
Member

ptrus commented Sep 17, 2021

Would be great if the following use-case of embedding enums would be supported:

#[derive(Clone, Debug, PartialEq, cbor::Encode, cbor::Decode)]
pub enum B { 
  #[cbor(rename="b_variant")]
  BVariant,
  #[cbor(rename="b_variant2")]
  BVariant2,
}

#[derive(Clone, Debug, PartialEq, cbor::Encode, cbor::Decode)]
pub enum A {
  #[cbor(rename="a_variant")]
  AVariant,
  #[cbor(embed)]
  Embed(B),
}

Where A would result in a "merged/flattened" enum being able to deserialize serialied B enums.

Current workaround requires manually "embedding" B enum vairants into A:

#[derive(Clone, Debug, PartialEq, cbor::Encode, cbor::Decode)]
pub enum A {
  #[cbor(rename="a_variant")]
  AVariant,
  #[cbor(rename="b_variant")]
  BVariant,
  #[cbor(rename="b_variant2")]
  BVariant2,
}

Related serde issue:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants