use serde::{Deserialize, Deserializer}; #[derive(Debug, Clone, Copy)] pub enum Driver { Gpio, Piface, } impl<'de> Deserialize<'de> for Driver { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { match String::deserialize(deserializer)?.as_str() { "gpio" => Ok(Driver::Gpio), "piface" => Ok(Driver::Piface), _ => Err(serde::de::Error::custom("invalid driver")), } } }