http_types_2/mime/
constants.rs

1use crate::mime::Mime;
2use std::borrow::Cow;
3
4macro_rules! utf8_mime_const {
5    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
6        mime_const!(
7            with_params,
8            $name,
9            $desc,
10            $base,
11            $sub,
12            true,
13            ";charset=utf-8"
14        );
15    };
16}
17macro_rules! mime_const {
18    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
19        mime_const!(with_params, $name, $desc, $base, $sub, false, "");
20    };
21
22    (with_params, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
23        mime_const!(
24            doc_expanded,
25            $name,
26            $desc,
27            $base,
28            $sub,
29            $is_utf8,
30            concat!(
31                "Content-Type for ",
32                $desc,
33                ".\n\n# Mime Type\n\n```text\n",
34                $base,
35                "/",
36                $sub,
37                $doccomment,
38                "\n```"
39            )
40        );
41    };
42
43    (doc_expanded, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
44        #[doc = $doccomment]
45        pub const $name: Mime = Mime {
46            essence: Cow::Borrowed(concat!($base, "/", $sub)),
47            basetype: Cow::Borrowed($base),
48            subtype: Cow::Borrowed($sub),
49            is_utf8: $is_utf8,
50            params: vec![],
51        };
52    };
53}
54
55utf8_mime_const!(JAVASCRIPT, "JavaScript", "text", "javascript");
56utf8_mime_const!(CSS, "CSS", "text", "css");
57utf8_mime_const!(HTML, "HTML", "text", "html");
58utf8_mime_const!(PLAIN, "Plain text", "text", "plain");
59utf8_mime_const!(XML, "XML", "application", "xml");
60utf8_mime_const!(RSS, "RSS Feed", "application", "rss+xml");
61utf8_mime_const!(ATOM, "Atom Feed", "application", "atom+xml");
62mime_const!(ANY, "matching anything", "*", "*");
63mime_const!(JSON, "JSON", "application", "json");
64mime_const!(SSE, "Server Sent Events", "text", "event-stream");
65mime_const!(BYTE_STREAM, "byte streams", "application", "octet-stream");
66mime_const!(FORM, "forms", "application", "x-www-form-urlencoded");
67mime_const!(MULTIPART_FORM, "multipart forms", "multipart", "form-data");
68mime_const!(WASM, "webassembly", "application", "wasm");
69
70// Images
71// https://www.iana.org/assignments/media-types/media-types.xhtml#image
72mime_const!(BMP, "BMP images", "image", "bmp");
73mime_const!(JPEG, "JPEG images", "image", "jpeg");
74mime_const!(PNG, "PNG images", "image", "png");
75mime_const!(SVG, "SVG", "image", "svg+xml");
76mime_const!(WEBP, "WebP images", "image", "webp");
77
78// Audio
79// https://www.iana.org/assignments/media-types/media-types.xhtml#audio
80mime_const!(MIDI, "MIDI audio", "audio", "midi");
81mime_const!(MP3, "MPEG audio layer 3", "audio", "mpeg");
82mime_const!(OGG, "Ogg vorbis audio", "audio", "ogg");
83mime_const!(OPUS, "Opus audio", "audio", "opus");
84mime_const!(M4A, "MPEG audio layer 4", "audio", "mp4");
85
86// Video
87// https://www.iana.org/assignments/media-types/media-types.xhtml#video
88mime_const!(MP4, "MPEG video layer 4", "video", "mp4");
89mime_const!(MPEG, "MPEG video", "video", "mpeg");
90mime_const!(WEBM, "WebM video", "video", "webm");
91mime_const!(AVI, "Microsoft AVI video", "video", "x-msvideo");
92// There are multiple `.ico` mime types known, but `image/x-icon`
93// is what most browser use. See:
94// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
95mime_const!(ICO, "ICO icons", "image", "x-icon");
96
97// Fonts
98// https://www.iana.org/assignments/media-types/media-types.xhtml#font
99mime_const!(OTF, "OTF", "font", "otf");
100mime_const!(TTF, "TTF", "font", "ttf");
101mime_const!(WOFF, "WOFF", "font", "woff");
102mime_const!(WOFF2, "WOFF2", "font", "woff2");
103
104// Archives
105mime_const!(ZIP, "Zip archive", "application", "zip");
106mime_const!(SEVENZIP, "7Zip archive", "application", "x-7z-compressed");