Skip to main content

EmbeddedFinder

Struct EmbeddedFinder 

Source
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

Source

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).

Source

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.

Source

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));
Source

pub fn get_tz_names(&self, lng: f64, lat: f64) -> Vec<&str>

Returns all matching timezone names, sorted lexicographically. Always polygon-exact.

Source

pub fn timezonenames(&self) -> Vec<&str>

Returns all timezone names in the dataset.

Source

pub fn data_version(&self) -> &str

Returns the dataset release this finder was built from (e.g. 2026c).

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for EmbeddedFinder

Available on crate features bundled or full only.
Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.