From 8dede6ceba3ebf71ee1bbf41d635b5f4694b17e6 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Fri, 30 Aug 2024 16:36:50 +0100 Subject: [PATCH] More efficient DevicePath parsing --- src/macros.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 9495b9c..ef0b29b 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -335,16 +335,17 @@ macro_rules! rpc_mod { impl<'de> Deserialize<'de> for DevicePath { fn deserialize>(deserializer: D) -> Result { - 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) } }