use std::{ops::Deref, str::FromStr}; use crate::formula::Formula; pub enum Boolean { Yes, No, } impl FromStr for Boolean { type Err = String; fn from_str(raw: &str) -> Result { match raw.to_lowercase().as_ref() { "" | "true" | "yes" => Ok(Self::Yes), "false" | "no" => Ok(Self::No), str => Err(format!("'{str}' is not a boolean value. try yes/no")), } } } impl Deref for Boolean { type Target = bool; fn deref(&self) -> &Self::Target { match self { Self::Yes => &true, Self::No => &false, } } } pub struct BooleanFormula; impl BooleanFormula { pub fn new() -> Self { Self {} } } impl From for Formula { fn from(_value: BooleanFormula) -> Self { Formula::new("failed to parse [opt] as a boolean") } }