http_types/mime/
constants.rs

1use crate::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", "application", "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");
60mime_const!(ANY, "matching anything", "*", "*");
61mime_const!(JSON, "JSON", "application", "json");
62mime_const!(SVG, "SVG", "image", "svg+xml");
63mime_const!(PNG, "PNG images", "image", "png");
64mime_const!(JPEG, "JPEG images", "image", "jpeg");
65mime_const!(SSE, "Server Sent Events", "text", "event-stream");
66mime_const!(BYTE_STREAM, "byte streams", "application", "octet-stream");
67mime_const!(FORM, "forms", "application", "x-www-form-urlencoded");
68mime_const!(MULTIPART_FORM, "multipart forms", "multipart", "form-data");
69mime_const!(WASM, "webassembly", "application", "wasm");
70// There are multiple `.ico` mime types known, but `image/x-icon`
71// is what most browser use. See:
72// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
73mime_const!(ICO, "ICO icons", "image", "x-icon");