Skip to main content

rocket_include_handlebars/debug/
macros.rs

1/// Used in the fairing of `HandlebarsResponse` to include Handlebars files into your executable binary file. You need to specify each file's name and its path relative to the directory containing the manifest of your package. In order to reduce the compilation time and allow to hot-reload templates, files are compiled into your executable binary file together, only when you are using the **release** profile.
2#[macro_export]
3macro_rules! handlebars_resources_initialize {
4    ( $handlebars:expr, $(,)* ) => {{}};
5    ( $handlebars:expr, $($name:expr => $path:expr),+ $(,)* ) => {{
6        let mut names = ::std::collections::HashSet::new();
7
8        $(
9            let name: &'static str = $name;
10
11            if !names.insert(name) {
12                panic!("The name `{}` is duplicated.", name);
13            }
14
15            $handlebars.register_template_file(name, $crate::manifest_dir_macros::not_directory_path!($path)).unwrap();
16        )+
17    }};
18}
19
20/// Used for wrapping a `HandlebarsResponse` and its constructor, and use a **key** to cache its HTML and ETag in memory. The cache is generated only when you are using the **release** profile.
21#[macro_export]
22macro_rules! handlebars_response_cache {
23    ($cm:expr, $etag_if_none_match:expr, $key:expr, $gen:block) => {{
24        #[allow(unused_variables)]
25        let __a = &$cm;
26        #[allow(unused_variables)]
27        let __a = &$key;
28
29        let etag_if_none_match: &$crate::EtagIfNoneMatch<'_> = &$etag_if_none_match;
30        // Copy the condition before the generator can take it.
31        let etag_if_none_match = ::std::clone::Clone::clone(etag_if_none_match);
32        let res = $gen;
33
34        res.check_etag(&etag_if_none_match)
35    }};
36}