blob: 5412c4c820afc5cc57a50ac18da0b836a1274d38 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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<Self, Self::Err> {
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<BooleanFormula> for Formula<Boolean> {
fn from(_value: BooleanFormula) -> Self {
Formula::new("failed to parse [opt] as a boolean")
}
}
|