common/emgauwa-controller/src/driver.rs

21 lines
430 B
Rust
Raw Normal View History

2023-11-24 23:39:44 +00:00
use serde::{Deserialize, Deserializer};
#[derive(Debug, Clone, Copy)]
pub enum Driver {
2023-11-27 11:49:40 +00:00
Gpio,
Piface,
2023-11-24 23:39:44 +00:00
}
impl<'de> Deserialize<'de> for Driver {
2023-11-27 11:49:40 +00:00
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
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")),
}
}
}