pub struct EmbeddedFinder { /* private fields */ }Expand description
The low-memory finder: queries TZF embedded binary (.tzb) bytes in
place, without expanding the geometry. Total footprint is roughly the file
itself (the bundled lite data is ~4 MB) plus the timezone names and a
16-bytes-per-16-chunks skip table built while validating the file at open
(~6 KB for lite, ~20 KB for full at the encoder’s default 256-point
chunks).
get_tz_name consults the file’s FUZZY preindex first and falls back to
the compressed-geometry scan; results match DefaultFinder over the
same file, only slower (microseconds instead of hundreds of nanoseconds
on boundary queries).
Implementations§
Source§impl EmbeddedFinder
impl EmbeddedFinder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates the finder over the bundled tzf-dist lite .tzb data,
borrowed in place from the executable’s read-only data segment.
§Panics
Panics when the embedded dataset is malformed (release-validated).
Sourcepub fn from_tzb(data: impl Into<Cow<'static, [u8]>>) -> Result<Self, Error>
pub fn from_tzb(data: impl Into<Cow<'static, [u8]>>) -> Result<Self, Error>
Builds a finder that queries data in place. Accepts borrowed
&'static [u8] (e.g. include_bytes!) without copying, or an owned
Vec<u8> (e.g. a file read at startup).
§Errors
Returns Error when the bytes are not a structurally valid
E-profile (.tzb) file. Memory images (.tzm) are rejected with
Error::Profile — they exist for the Go runtime and offer no
benefit here.
Sourcepub fn get_tz_name(&self, lng: f64, lat: f64) -> &str
pub fn get_tz_name(&self, lng: f64, lat: f64) -> &str
Returns the first matching timezone name, or "" when no timezone
covers the point.
use tzf_rs::EmbeddedFinder;
let finder = EmbeddedFinder::new();
assert_eq!("Asia/Shanghai", finder.get_tz_name(116.3883, 39.9289));Sourcepub fn get_tz_names(&self, lng: f64, lat: f64) -> Vec<&str>
pub fn get_tz_names(&self, lng: f64, lat: f64) -> Vec<&str>
Returns all matching timezone names, sorted lexicographically. Always polygon-exact.
Sourcepub fn timezonenames(&self) -> Vec<&str>
pub fn timezonenames(&self) -> Vec<&str>
Returns all timezone names in the dataset.
Sourcepub fn data_version(&self) -> &str
pub fn data_version(&self) -> &str
Returns the dataset release this finder was built from (e.g. 2026c).
Sourcepub fn to_geojson(&self) -> BoundaryFile
pub fn to_geojson(&self) -> BoundaryFile
Converts all timezone boundaries to a GeoJSON FeatureCollection.
Unlike DefaultFinder, which exports polygons it already holds,
this decodes the whole file’s geometry on demand — roughly the cost of
loading an expanded finder. A timezone that fails to decode is
omitted; use get_tz_geojson when the error matters.
Sourcepub fn get_tz_geojson(&self, timezone_name: &str) -> Option<BoundaryFile>
pub fn get_tz_geojson(&self, timezone_name: &str) -> Option<BoundaryFile>
Converts one timezone’s boundaries to a GeoJSON FeatureCollection,
decoding only that timezone’s rings. Returns None when the dataset
does not contain the name or its geometry fails to decode.
Sourcepub fn get_tz_preindex_geojson(
&self,
timezone_name: &str,
) -> Option<BoundaryFile>
pub fn get_tz_preindex_geojson( &self, timezone_name: &str, ) -> Option<BoundaryFile>
Converts one timezone’s FUZZY preindex tiles to a GeoJSON
FeatureCollection; see DefaultFinder::get_tz_preindex_geojson.
Results match DefaultFinder over the same file.
Sourcepub fn to_preindex_geojson(&self) -> Option<BoundaryFile>
pub fn to_preindex_geojson(&self) -> Option<BoundaryFile>
Converts the whole FUZZY preindex to a GeoJSON FeatureCollection; see
DefaultFinder::to_preindex_geojson. Results match
DefaultFinder over the same file.