brainfuck/
debug_format.rs

1use std::str::FromStr;
2
3#[derive(Debug, PartialEq, Eq, Clone, Copy)]
4pub enum DebugFormat {
5    /// Human readable text format
6    Text,
7    /// Machine readable JSON format
8    Json,
9}
10
11impl FromStr for DebugFormat {
12    type Err = ();
13
14    fn from_str(val: &str) -> Result<Self, Self::Err> {
15        match val {
16            "text" => Ok(DebugFormat::Text),
17            "json" => Ok(DebugFormat::Json),
18            _ => Err(()),
19        }
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn from_str() {
29        let opt: DebugFormat = "text".parse().unwrap();
30        assert_eq!(opt, DebugFormat::Text);
31        let opt: DebugFormat = "json".parse().unwrap();
32        assert_eq!(opt, DebugFormat::Json);
33
34        assert!("foo".parse::<DebugFormat>().is_err());
35    }
36}