http_types/mime/
constants.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::Mime;
use std::borrow::Cow;

macro_rules! utf8_mime_const {
    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
        mime_const!(
            with_params,
            $name,
            $desc,
            $base,
            $sub,
            true,
            ";charset=utf-8"
        );
    };
}
macro_rules! mime_const {
    ($name:ident, $desc:expr, $base:expr, $sub:expr) => {
        mime_const!(with_params, $name, $desc, $base, $sub, false, "");
    };

    (with_params, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
        mime_const!(
            doc_expanded,
            $name,
            $desc,
            $base,
            $sub,
            $is_utf8,
            concat!(
                "Content-Type for ",
                $desc,
                ".\n\n# Mime Type\n\n```text\n",
                $base,
                "/",
                $sub,
                $doccomment,
                "\n```"
            )
        );
    };

    (doc_expanded, $name:ident, $desc:expr, $base:expr, $sub:expr, $is_utf8:expr, $doccomment:expr) => {
        #[doc = $doccomment]
        pub const $name: Mime = Mime {
            essence: Cow::Borrowed(concat!($base, "/", $sub)),
            basetype: Cow::Borrowed($base),
            subtype: Cow::Borrowed($sub),
            is_utf8: $is_utf8,
            params: vec![],
        };
    };
}

utf8_mime_const!(JAVASCRIPT, "JavaScript", "application", "javascript");
utf8_mime_const!(CSS, "CSS", "text", "css");
utf8_mime_const!(HTML, "HTML", "text", "html");
utf8_mime_const!(PLAIN, "Plain text", "text", "plain");
utf8_mime_const!(XML, "XML", "application", "xml");
mime_const!(ANY, "matching anything", "*", "*");
mime_const!(JSON, "JSON", "application", "json");
mime_const!(SVG, "SVG", "image", "svg+xml");
mime_const!(PNG, "PNG images", "image", "png");
mime_const!(JPEG, "JPEG images", "image", "jpeg");
mime_const!(SSE, "Server Sent Events", "text", "event-stream");
mime_const!(BYTE_STREAM, "byte streams", "application", "octet-stream");
mime_const!(FORM, "forms", "application", "x-www-form-urlencoded");
mime_const!(MULTIPART_FORM, "multipart forms", "multipart", "form-data");
mime_const!(WASM, "webassembly", "application", "wasm");
// There are multiple `.ico` mime types known, but `image/x-icon`
// is what most browser use. See:
// https://en.wikipedia.org/wiki/ICO_%28file_format%29#MIME_type
mime_const!(ICO, "ICO icons", "image", "x-icon");