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

Added support for newtype structs and serde flatten #110

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

ohadravid
Copy link
Owner

This PR adds support for two related things: newtype-structs and serde flatten.

Example for newtype-structs:

#[derive(Deserialize, Debug)]
struct Win32_OperatingSystem(pub HashMap<String, Variant>);

let system = wmi_con.query::<Win32_OperatingSystem>().unwrap();

Example for serde-flatten:

// 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();

// Or, using a newtype wrapper:

#[derive(Deserialize, Debug)]
#[serde(rename = "Win32_OperatingSystem")]
struct Win32_OperatingSystemWrapper(pub Win32_OperatingSystem);
let system = wmi_con.query::<Win32_OperatingSystemWrapper>().unwrap();

(Regular .query cannot work because of serde-rs/serde#1346)

Fixes #109

@ohadravid ohadravid merged commit 0895401 into main Jan 29, 2025
8 checks passed
@ohadravid ohadravid deleted the feature/serde-flatten branch January 29, 2025 18:42
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 this pull request may close these issues.

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