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

[Bug] Newtype enum variant deserialization failure when used with #[serde(flatten)] #14

Open
greenhat616 opened this issue Oct 3, 2024 · 0 comments · May be fixed by #15
Open

[Bug] Newtype enum variant deserialization failure when used with #[serde(flatten)] #14

greenhat616 opened this issue Oct 3, 2024 · 0 comments · May be fixed by #15
Labels
bug Something isn't working

Comments

@greenhat616
Copy link

greenhat616 commented Oct 3, 2024

previous repo issue: dtolnay/serde-yaml#344

playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5149fbeb995a06e94ecb7e4508ca3b0c

And I have test it via serde_yaml_ng::from_value::<EnumTy>::(&value) , it report the same error too.

The sample enum could be:

#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub enum ProfileItemType {
    #[serde(rename = "remote")]
    Remote,
    #[serde(rename = "local")]
    #[default]
    Local,
    #[serde(rename = "script")]
    Script(ScriptType),
    #[serde(rename = "merge")]
    Merge,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, Eq, PartialEq, Hash)]
pub enum ScriptType {
    #[default]
    #[serde(rename = "javascript")]
    JavaScript,
    #[serde(rename = "lua")]
    Lua,
}

#[derive(Default, Debug, Clone, Deserialize, Serialize, Builder, BuilderUpdate)]
pub struct ProfileShared {
    /// profile item type
    /// enum value: remote | local | script | merge
    #[serde(rename = "type")]
    pub r#type: ProfileItemType,
}

#[derive(Default, Delegate, Debug, Clone, Deserialize, Serialize, Builder, BuilderUpdate)]
pub struct MergeProfile {
    #[serde(flatten)]
    pub shared: ProfileShared, // <-- This would be failed when deserialization 
}

Besides the #[serde(flatten)] usage, Just pass a Value::TaggedValue to serde_yaml::from_value always failed.

Any ideas could be shared here? Thank you.

@greenhat616 greenhat616 linked a pull request Oct 7, 2024 that will close this issue
@acatton acatton added the bug Something isn't working label Oct 9, 2024
greenhat616 added a commit to libnyanpasu/serde-yaml-ng that referenced this issue Oct 21, 2024
Close acatton#14.

I adapted the implementation from [ron-rs/ron#451](ron-rs/ron#451).

This is a workaround for Serde's internal buffer type used when deserializing via `visit_enum`.
greenhat616 added a commit to libnyanpasu/serde-yaml-ng that referenced this issue Oct 21, 2024
Close acatton#14.

I adapted the implementation from [ron-rs/ron#451](ron-rs/ron#451).

This is a workaround for Serde's internal buffer type used when deserializing via `visit_enum`.
greenhat616 added a commit to libnyanpasu/serde-yaml-ng that referenced this issue Nov 4, 2024
Close acatton#14.

I adapted the implementation from [ron-rs/ron#451](ron-rs/ron#451).

This is a workaround for Serde's internal buffer type used when deserializing via `visit_enum`.

Signed-off-by: Jonson Petard <41122242+greenhat616@users.noreply.github.com>
greenhat616 added a commit to libnyanpasu/serde-yaml-ng that referenced this issue Nov 4, 2024
Close acatton#14.

I adapted the implementation from [ron-rs/ron#451](ron-rs/ron#451).

This is a workaround for Serde's internal buffer type used when deserializing via `visit_enum`.

Signed-off-by: Jonson Petard <41122242+greenhat616@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants