use std::collections::HashMap;
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PinMode {
Always,
#[default]
Retrieved,
}
impl PinMode {
pub fn as_str(&self) -> &'static str {
match self {
PinMode::Always => "always",
PinMode::Retrieved => "retrieved",
}
}
}
impl fmt::Display for PinMode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsePinModeError(pub String);
impl fmt::Display for ParsePinModeError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"unknown pin mode {:?} (expected \"always\" or \"retrieved\")",
self.0
)
}
}
impl std::error::Error for ParsePinModeError {}
impl FromStr for PinMode {
type Err = ParsePinModeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"always" => Ok(PinMode::Always),
"retrieved" => Ok(PinMode::Retrieved),
other => Err(ParsePinModeError(other.to_string())),
}
}
}
pub struct Fact {
pub id: String,
pub name: String,
pub description: String,
pub tags: Vec<String>,
pub metadata: HashMap<String, Vec<String>>,
pub body: String,
pub pin: PinMode,
}