zugferd_code_lists/zugferd_2_3_2/
mime.rs

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