yatp_cli/
format.rs

1use clap::ValueEnum;
2
3/// Image format
4#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
5pub enum ImageFormat {
6    /// PNG
7    Png,
8    /// JPEG
9    Jpeg,
10    /// BMP
11    Bmp,
12}
13
14/// Dictionary Format
15#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
16pub enum DictionaryFormat {
17    /// TOML
18    Toml,
19    /// JSON
20    Json,
21    /// YAML
22    Yaml,
23    /// RON
24    Ron,
25}
26
27impl Default for ImageFormat {
28    fn default() -> Self {
29        Self::Png
30    }
31}
32
33impl Default for DictionaryFormat {
34    fn default() -> Self {
35        Self::Json
36    }
37}
38
39impl ImageFormat {
40    /// Extension of a given image format:
41    /// - png => .png
42    /// - jpeg => .jpeg
43    /// - bmp => .bmp
44    pub fn ext(&self) -> &str {
45        match self {
46            ImageFormat::Png => "png",
47            ImageFormat::Jpeg => "jpeg",
48            ImageFormat::Bmp => "bmp",
49        }
50    }
51
52    /// Converts an image format to `image`'s equivalent
53    pub fn as_image_format(&self) -> image::ImageFormat {
54        match self {
55            ImageFormat::Png => image::ImageFormat::Png,
56            ImageFormat::Jpeg => image::ImageFormat::Jpeg,
57            ImageFormat::Bmp => image::ImageFormat::Bmp,
58        }
59    }
60}
61
62impl DictionaryFormat {
63    /// Extension of a given dictionary format:
64    /// - toml => .toml
65    /// - json => .json
66    /// - yaml => .yaml
67    /// - ron => .ron
68    pub fn ext(&self) -> &str {
69        match self {
70            DictionaryFormat::Toml => "toml",
71            DictionaryFormat::Json => "json",
72            DictionaryFormat::Yaml => "yaml",
73            DictionaryFormat::Ron => "ron",
74        }
75    }
76}