Skip to content

Commit

Permalink
Added support for unit enum desr
Browse files Browse the repository at this point in the history
  • Loading branch information
ohadravid committed Feb 17, 2024
1 parent fa4ef68 commit a1d788e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/de/variant_de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{de::wbem_class_de::Deserializer, variant::Variant, WMIError};
use serde::{de, forward_to_deserialize_any, Deserialize};
use serde::{de::{self, IntoDeserializer}, forward_to_deserialize_any, Deserialize};
use std::{fmt, vec::IntoIter};

#[derive(Debug)]
Expand Down Expand Up @@ -84,15 +84,18 @@ impl<'de> serde::Deserializer<'de> for Variant {
fn deserialize_enum<V>(
self,
name: &'static str,
fields: &'static [&'static str],
variants: &'static [&'static str],
visitor: V,
) -> Result<V::Value, Self::Error>
where
V: de::Visitor<'de>,
{
match self {
Variant::Object(o) => {
Deserializer::from_wbem_class_obj(o).deserialize_enum(name, fields, visitor)
Deserializer::from_wbem_class_obj(o).deserialize_enum(name, variants, visitor)
}
Variant::String(str) => {
str.into_deserializer().deserialize_enum(name, variants, visitor)
}
_ => self.deserialize_any(visitor),
}
Expand Down
22 changes: 22 additions & 0 deletions src/de/wbem_class_de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,26 @@ mod tests {

assert!(matches!(proc.TargetInstance, Instance::Process(..)))
}

#[test]
fn it_can_desr_unit_enum_field_from_string() {
let wmi_con = wmi_con();

#[derive(Deserialize, Debug, PartialEq, Eq)]
enum Status {
OK,
}

#[derive(Deserialize, Debug)]
struct Win32_OperatingSystem {
Status: Status,
}

let os: Win32_OperatingSystem = wmi_con
.get()
.unwrap();

assert_eq!(os.Status, Status::OK);
}

}

0 comments on commit a1d788e

Please sign in to comment.