Skip to main content

routers_tz/
lib.rs

1pub mod interface;
2pub mod model;
3pub mod storage;
4
5pub(crate) mod generated {
6    //! Pre-baked backend data shipped with the crate. The bytes are produced
7    //! by `build.rs` from the timezone geojson and committed into
8    //! `data/prebuilt/`, so consumers never need the (very large) source
9    //! geojson to build.
10
11    // The `basic` backend's pre-built data is ~113 MiB (every timezone
12    // polygon, serialised) and is not shipped in the published crate. It's
13    // produced by `build.rs` when the source geojson is present locally; in
14    // that case `build.rs` sets the `have_basic_prebuilt` cfg.
15    #[cfg(all(feature = "basic", have_basic_prebuilt))]
16    pub mod basic {
17        use lazy_static::lazy_static;
18        use routers_tz_types::storage::basic::BasicStorageBackend;
19
20        const DATA: &[u8] = include_bytes!("../data/prebuilt/basic_timezone_data.postcard.bin");
21
22        lazy_static! {
23            pub static ref STORAGE: BasicStorageBackend =
24                postcard::from_bytes(DATA).expect("Failed to deserialize basic timezone data");
25        }
26
27        pub fn storage() -> &'static BasicStorageBackend {
28            &STORAGE
29        }
30    }
31
32    #[cfg(all(feature = "basic", not(have_basic_prebuilt)))]
33    compile_error!(
34        "The `basic` feature requires the timezone-boundary-builder geojson \
35         at `data/<tz_version>/timezones.geojson` so `build.rs` can generate \
36         `data/prebuilt/basic_timezone_data.postcard.bin`. The pre-built \
37         binary is too large (~113 MiB) to ship via crates.io. Either disable \
38         the `basic` feature (the default is `s2cell`), or build from a git \
39         checkout with the geojson present."
40    );
41
42    #[cfg(feature = "rtree")]
43    pub mod rtree {
44        use lazy_static::lazy_static;
45        use routers_tz_types::storage::rtree::RTreeStorageBackend;
46
47        const DATA: &[u8] = include_bytes!("../data/prebuilt/rtree_timezone_data.postcard.bin");
48
49        lazy_static! {
50            pub static ref STORAGE: RTreeStorageBackend =
51                postcard::from_bytes(DATA).expect("Failed to deserialize rtree timezone data");
52        }
53
54        pub fn storage() -> &'static RTreeStorageBackend {
55            &STORAGE
56        }
57    }
58
59    #[cfg(feature = "s2cell")]
60    pub mod s2cell {
61        use lazy_static::lazy_static;
62        use routers_tz_types::storage::s2cell::S2StorageBackend;
63
64        const DATA: &[u8] = include_bytes!("../data/prebuilt/s2cell_timezone_data.postcard.bin");
65
66        lazy_static! {
67            pub static ref STORAGE: S2StorageBackend =
68                postcard::from_bytes(DATA).expect("Failed to deserialize s2cell timezone data");
69        }
70
71        pub fn storage() -> &'static S2StorageBackend {
72            &STORAGE
73        }
74    }
75}
76
77// Trait Definition
78pub use interface::TimezoneResolver;
79
80// Timezone Type
81pub use routers_tz_types::TimeZone;
82
83// Basic Storage Impl
84#[cfg(feature = "basic")]
85pub use storage::basic::BasicStorage;
86
87// RTree Storage Impl
88#[cfg(feature = "rtree")]
89pub use storage::rtree::RTreeStorage;
90
91// S2Cell Storage Impl
92#[cfg(feature = "s2cell")]
93pub use storage::s2cell::S2CellStorage;