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
use crate::Parse;
use std::fmt;

#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub enum OverflowMode {
    #[default]
    None,
    Clip,
}

#[derive(Debug, PartialEq, Eq)]
pub struct ParseOverflowError;

impl Parse for OverflowMode {
    type Err = ();

    fn parse(value: &str) -> Result<Self, Self::Err> {
        Ok(match value {
            "clip" => OverflowMode::Clip,
            _ => OverflowMode::None,
        })
    }
}

impl fmt::Display for OverflowMode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(match self {
            OverflowMode::Clip => "clip",
            OverflowMode::None => "none",
        })
    }
}