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 = ();
33    fn from_str(s: &str) -> Result<Self, Self::Err> {
34        <Self as crate::FromCode>::from_code(s).ok_or(())
35    }
36}
37
38impl crate::Code for MIME {
39    fn code(self) -> &'static str {
40        match self {
41            MIME::ApplicationPdf => "application/pdf",
42            MIME::ImagePng => "image/png",
43            MIME::ImageJpeg => "image/jpeg",
44            MIME::TextCsv => "text/csv",
45            MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet => {
46                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
47            }
48            MIME::ApplicationVndOasisOpendocumentSpreadsheet => {
49                "application/vnd.oasis.opendocument.spreadsheet"
50            }
51            MIME::ApplicationXml => "application/xml",
52            MIME::TextXml => "text/xml",
53        }
54    }
55}
56
57impl crate::Description for MIME {
58    fn description(self) -> &'static str {
59        match self {
60            MIME::ApplicationPdf => "application/pdf",
61            MIME::ImagePng => "image/png",
62            MIME::ImageJpeg => "image/jpeg",
63            MIME::TextCsv => "text/csv",
64            MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet => {
65                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
66            }
67            MIME::ApplicationVndOasisOpendocumentSpreadsheet => {
68                "application/vnd.oasis.opendocument.spreadsheet"
69            }
70            MIME::ApplicationXml => "application/xml",
71            MIME::TextXml => "text/xml",
72        }
73    }
74}
75
76impl crate::FromCode for MIME {
77    fn from_code(code: &str) -> Option<Self>
78    where
79        Self: Sized,
80    {
81        match code {
82            "application/pdf" => Some(MIME::ApplicationPdf),
83            "image/png" => Some(MIME::ImagePng),
84            "image/jpeg" => Some(MIME::ImageJpeg),
85            "text/csv" => Some(MIME::TextCsv),
86            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" => {
87                Some(MIME::ApplicationVndOpenxmlformatsOfficedocumentSpreadsheetmlSheet)
88            }
89            "application/vnd.oasis.opendocument.spreadsheet" => {
90                Some(MIME::ApplicationVndOasisOpendocumentSpreadsheet)
91            }
92            "application/xml" => Some(MIME::ApplicationXml),
93            "text/xml" => Some(MIME::TextXml),
94            _ => None,
95        }
96    }
97}