Skip to content

Commit

Permalink
More efficient DevicePath parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Aug 30, 2024
1 parent 0b6c067 commit 8dede6c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,17 @@ macro_rules! rpc_mod {

impl<'de> Deserialize<'de> for DevicePath {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Ok(DevicePath(match String::deserialize(deserializer)?.as_str() {
#[derive(Deserialize)]
#[serde(remote = "DeviceType")]
enum DevicePathRepr {
$(
#[cfg(feature = $path)]
$path => DeviceType::$trait_name,
#[serde(rename = $path)]
$trait_name,
)*
other => return Err(serde::de::Error::unknown_variant(other, &[ $(
#[cfg(feature = $path)]
$path
),* ])),
}))
}

DevicePathRepr::deserialize(deserializer).map(Self)
}
}

Expand Down

0 comments on commit 8dede6c

Please sign in to comment.