remote_settings/
macros.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#[macro_export]
6macro_rules! packaged_collections {
7    ($(($bucket:expr, $collection:expr)),* $(,)?) => {
8        fn get_packaged_data(collection_name: &str) -> Option<&'static str> {
9            match collection_name {
10                $($collection => Some(include_str!(concat!(
11                    env!("CARGO_MANIFEST_DIR"),
12                    "/dumps/",
13                    $bucket,
14                    "/",
15                    $collection,
16                    ".json"
17                ))),)*
18                _ => None,
19            }
20        }
21
22        /// Get just the timestamp, which is stored separately. This allows
23        /// checking which data is newer without paying the cost of parsing
24        /// the full packaged JSON.
25        fn get_packaged_timestamp(collection_name: &str) -> Option<u64> {
26            match collection_name {
27                $($collection => {
28                    let timestamp_str = include_str!(concat!(
29                        env!("CARGO_MANIFEST_DIR"),
30                        "/dumps/",
31                        $bucket,
32                        "/",
33                        $collection,
34                        ".timestamp"
35                    ));
36                    timestamp_str.trim().parse().ok()
37                }),*
38                _ => None,
39            }
40        }
41    };
42}
43
44#[macro_export]
45macro_rules! packaged_attachments {
46    () => {
47        fn get_packaged_attachment(collection_name: &str, filename: &str) -> Option<(&'static [u8], &'static str)> {
48            None
49        }
50    };
51    ($(($bucket:expr, $collection:expr) => [$($filename:expr),* $(,)?]),* $(,)?) => {
52        fn get_packaged_attachment(collection_name: &str, filename: &str) -> Option<(&'static [u8], &'static str)> {
53            match (collection_name, filename) {
54                $($(
55                    ($collection, $filename) => Some((
56                        include_bytes!(concat!(
57                            env!("CARGO_MANIFEST_DIR"),
58                            "/dumps/",
59                            $bucket,
60                            "/attachments/",
61                            $collection,
62                            "/",
63                            $filename
64                        )),
65                        include_str!(concat!(
66                            env!("CARGO_MANIFEST_DIR"),
67                            "/dumps/",
68                            $bucket,
69                            "/attachments/",
70                            $collection,
71                            "/",
72                            $filename,
73                            ".meta.json"
74                        ))
75                    )),
76                )*)*
77                _ => None,
78            }
79        }
80    };
81}