zugferd_code_lists/zugferd_2_3_2/
mime.rs

1#![allow(non_camel_case_types)]
2
3#[cfg_attr(feature = "specta", derive(specta::Type))]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
6pub enum MIME {
7    /// application/pdf
8    ApplicationPdf,
9    /// image/png
10    ImagePng,
11    /// image/jpeg
12    ImageJpeg,
13    /// text/csv
14    TextCsv,
15    /// application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
16    ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet,
17    /// application/vnd.oasis.opendocument.spreadsheet
18    ApplicationVndOasisOpendocumentSpreadsheet,
19    /// application/xml
20    ApplicationXml,
21    /// text/xml
22    TextXml,
23}
24
25impl std::fmt::Display for MIME {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "{}", <Self as crate::Code>::code(*self))
28    }
29}
30
31impl std::str::FromStr for MIME {
32    type Err = crate::ParseError<Self>;
33    fn from_str(s: &str) -> Result<Self, Self::Err> {
34        <Self as crate::FromCode>::from_code(s)
35            .ok_or_else(|| crate::ParseError::<Self>::new(s.to_owned()))
36    }
37}
38
39impl crate::Code for MIME {
40    fn code(self) -> &'static str {
41        match self {
42            MIME::ApplicationPdf => "application/pdf",
43            MIME::ImagePng => "image/png",
44            MIME::ImageJpeg => "image/jpeg",
45            MIME::TextCsv => "text/csv",
46            MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet => {
47                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
48            }
49            MIME::ApplicationVndOasisOpendocumentSpreadsheet => {
50                "application/vnd.oasis.opendocument.spreadsheet"
51            }
52            MIME::ApplicationXml => "application/xml",
53            MIME::TextXml => "text/xml",
54        }
55    }
56}
57
58impl crate::Description for MIME {
59    fn description(self) -> &'static str {
60        match self {
61            MIME::ApplicationPdf => "application/pdf",
62            MIME::ImagePng => "image/png",
63            MIME::ImageJpeg => "image/jpeg",
64            MIME::TextCsv => "text/csv",
65            MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet => {
66                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
67            }
68            MIME::ApplicationVndOasisOpendocumentSpreadsheet => {
69                "application/vnd.oasis.opendocument.spreadsheet"
70            }
71            MIME::ApplicationXml => "application/xml",
72            MIME::TextXml => "text/xml",
73        }
74    }
75}
76
77impl crate::FromCode for MIME {
78    fn from_code(code: &str) -> Option<Self>
79    where
80        Self: Sized,
81    {
82        match code {
83            "application/pdf" => Some(MIME::ApplicationPdf),
84            "image/png" => Some(MIME::ImagePng),
85            "image/jpeg" => Some(MIME::ImageJpeg),
86            "text/csv" => Some(MIME::TextCsv),
87            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => {
88                Some(MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet)
89            }
90            "application/vnd.oasis.opendocument.spreadsheet" => {
91                Some(MIME::ApplicationVndOasisOpendocumentSpreadsheet)
92            }
93            "application/xml" => Some(MIME::ApplicationXml),
94            "text/xml" => Some(MIME::TextXml),
95            _ => None,
96        }
97    }
98}