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

Reopening: Feature request: Serde flatten for extra properties (derive Clone for Variant) #108 #109

Closed
ThalusA opened this issue Jan 29, 2025 · 1 comment · Fixed by #110

Comments

@ThalusA
Copy link

ThalusA commented Jan 29, 2025

Hi, I'm reopening this issue based on the fact that I have now another error. #108
Now I don't have any error doing #[serde(flatten)] pub extra: HashMap<String, Variant> while compiling but I have an error at runtime: Expected a named struct. Hint: You cannot use a HashMap<...> in this context because it requires the struct to have a name. I'm at the time trying to find a solution for that but it seems what I want to do doesn't seems possible yet

I just want to be able to do exactly that : https://serde.rs/attr-flatten.html#capture-additional-fields

@ohadravid
Copy link
Owner

See #110 for a more complete solution, but you can do this even without it using raw_query:

#[derive(Deserialize, Debug)]
struct Win32_OperatingSystem {
    Caption: String,
    Name: String,

    #[serde(flatten)]
    extra: HashMap<String, Variant>,
}

let system: Vec<Win32_OperatingSystem> = wmi_con
    .raw_query("SELECT * FROM Win32_OperatingSystem")
    .unwrap();

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