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