This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 160
Nested Enums? #363
Comments
You could try using https://docs.rs/serde_yaml/0.9/serde_yaml/with/singleton_map which does not have that limitation. use serde::{Serialize, Serializer};
#[derive(Serialize)]
#[serde(remote = "Self")]
pub enum ExprKind {
...
}
impl Serialize for ExprKind {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
struct ExternallyTaggedExprKind<'a>(&'a ExprKind);
impl<'a> Serialize for ExternallyTaggedExprKind<'a> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
ExprKind::serialize(self.0, serializer)
}
}
serde_yaml::with::singleton_map::serialize(&ExternallyTaggedExprKind(self), serializer)
}
} |
Thank you very much! I did this in PRQL/prql#2277 (I used just the derive approach from the docs, which seems to work well) Fine to close! |
azriel91
added a commit
to azriel91/peace
that referenced
this issue
May 19, 2023
…ort serializing nested enums. See <dtolnay/serde-yaml#363>.
Not trying to open up old questions but when you're here and you are looking for this just as I just did (for the second or third time lol): Check out the recursive version that allows Enums in HashMap, Vec etc. etc.: I'll just leave that here with greeting to future people (and me) who are googling a similar thing and finding this exact issue. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
We're great fans of serde, great fans of YAML — thank you very much for the library.
Is there any workaround to the
Error("serializing nested enums in YAML is not supported yet")
? We're tried removing nested enums from our AST, but aren't able to do this fully (PRQL/prql#2172 (comment)). We'd really like to represent our AST in something less verbose than JSON for human readability.I've tried various incarnations of https://serde.rs/enum-representations.html, but not yet successfully.
Thanks a lot...
The text was updated successfully, but these errors were encountered: