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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#[cfg(debug_assertions)]
/// Includes a file as a reference to a byte array (`&'static [u8]`).
///
/// The file is located relative to the directory containing the manifest of your package.
#[macro_export]
macro_rules! lazy_static_include_bytes {
    ( @impl $name:ident ) => {
        impl<'a> ::std::cmp::PartialEq<&'a [u8]> for $name {
            fn eq(&self, other: &&'a [u8]) -> bool {
                (&*$name).eq(other)
            }
        }

        impl ::std::cmp::PartialEq for $name {
            fn eq(&self, other: &$name) -> bool {
                true
            }
        }

        impl<'a> ::std::cmp::PartialEq<$name> for &'a [u8] {
            fn eq(&self, other: &$name) -> bool {
                self.eq(&*$name)
            }
        }

        impl ::std::fmt::Debug for $name {
            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                ::std::fmt::Debug::fmt(*$name, f)
            }
        }

        impl<T> ::std::convert::AsRef<T> for $name
        where
            T: ?Sized,
            [u8]: ::std::convert::AsRef<T>,
        {
            fn as_ref(&self) -> &T {
                (*$name).as_ref()
            }
        }
    };
    ( @inner $name:ident, $path:expr ) => {
        {
            use ::std::fs;
            use ::std::mem::{forget, transmute};

            let path = $crate::manifest_dir_macros::not_directory_path!($path);

            let data = fs::read(path).unwrap();

            unsafe {
                let ret = transmute(data.as_slice());
                forget(data);
                ret
            }
        }
    };
    ( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
        $crate::lazy_static::lazy_static! {
            $(#[$attr])*
            static ref $name: &'static [u8] = $crate::lazy_static_include_bytes!(@inner $name, $path);
        }

        $crate::lazy_static_include_bytes!(@impl $name);
    };
    ( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr ) => {
        $crate::lazy_static::lazy_static! {
            $(#[$attr])*
            pub$(($($v)+))? static ref $name: &'static [u8] = $crate::lazy_static_include_bytes!(@inner $name, $path);
        }

        $crate::lazy_static_include_bytes!(@impl $name);
    };
    ( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
        $(
            $crate::lazy_static_include_bytes! {
                @unit
                $(#[$attr])*
                $name => $path
            }
        )*
    };
    ( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
        $(
            $crate::lazy_static_include_bytes! {
                @unit
                $(#[$attr])*
                pub$(($($v)+))? $name => $path
            }
        )*
    };
}

#[cfg(not(debug_assertions))]
/// Includes a file as a reference to a byte array (`&'static [u8]`).
///
/// The file is located relative to the directory containing the manifest of your package.
#[macro_export]
macro_rules! lazy_static_include_bytes {
    ( @impl $name:ident ) => {
        impl<'a> ::std::cmp::PartialEq<&'a [u8]> for $name {
            fn eq(&self, other: &&'a [u8]) -> bool {
                (&*$name).eq(other)
            }
        }

        impl ::std::cmp::PartialEq for $name {
            fn eq(&self, other: &$name) -> bool {
                true
            }
        }

        impl<'a> ::std::cmp::PartialEq<$name> for &'a [u8] {
            fn eq(&self, other: &$name) -> bool {
                self.eq(&*$name)
            }
        }

        impl ::std::fmt::Debug for $name {
            fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                ::std::fmt::Debug::fmt(*$name, f)
            }
        }

        impl<T> ::std::convert::AsRef<T> for $name
        where
            T: ?Sized,
            [u8]: ::std::convert::AsRef<T>,
        {
            fn as_ref(&self) -> &T {
                (*$name).as_ref()
            }
        }
    };
    ( @unit $(#[$attr: meta])* $name:ident => $path:expr ) => {
        $crate::lazy_static::lazy_static! {
            $(#[$attr])*
            static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
        }

        $crate::lazy_static_include_bytes!(@impl $name);
    };
    ( @unit $(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr ) => {
        $crate::lazy_static::lazy_static! {
            $(#[$attr])*
            pub$(($($v)+))? static ref $name: &'static [u8] = include_bytes!($crate::manifest_dir_macros::path!($path));
        }

        $crate::lazy_static_include_bytes!(@impl $name);
    };
    ( $($(#[$attr: meta])* $name:ident => $path:expr),* $(,)* ) => {
        $(
            $crate::lazy_static_include_bytes! {
                @unit
                $(#[$attr])*
                $name => $path
            }
        )*
    };
    ( $($(#[$attr: meta])* pub$(($($v:tt)+))? $name:ident => $path:expr),* $(,)* ) => {
        $(
            $crate::lazy_static_include_bytes! {
                @unit
                $(#[$attr])*
                pub$(($($v)+))? $name => $path
            }
        )*
    };
}