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
45
46
use std::fmt;

/// Describes the format of the save before decoding
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Encoding {
    /// Plaintext
    Text,

    /// Plaintext documents within a zip file
    TextZip,

    /// Binary documents within a zip file
    BinaryZip,

    /// Binary
    Binary,
}

impl Encoding {
    pub fn as_str(&self) -> &'static str {
        match self {
            Encoding::Text => "text",
            Encoding::TextZip => "textzip",
            Encoding::BinaryZip => "binzip",
            Encoding::Binary => "binary",
        }
    }

    pub fn is_binary(&self) -> bool {
        matches!(self, Encoding::BinaryZip | Encoding::Binary)
    }

    pub fn is_text(&self) -> bool {
        matches!(self, Encoding::TextZip | Encoding::Text)
    }

    pub fn is_zip(&self) -> bool {
        matches!(self, Encoding::BinaryZip | Encoding::TextZip)
    }
}

impl fmt::Display for Encoding {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.as_str())
    }
}