use crate::PhoneNumber;
mod binary;
mod prefix;
use prefix::PrefixTable;
#[cfg(feature = "geocoding")]
const LOCATIONS: PrefixTable =
PrefixTable::new(include_bytes!("enrichment/artifacts/locations.bin"));
#[cfg(feature = "carrier")]
const CARRIER_NAMES: PrefixTable =
PrefixTable::new(include_bytes!("enrichment/artifacts/carrier_names.bin"));
#[cfg(feature = "timezone")]
const TIME_ZONES: PrefixTable =
PrefixTable::new(include_bytes!("enrichment/artifacts/time_zones.bin"));
#[cfg(feature = "geocoding")]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Location(&'static str);
#[cfg(feature = "geocoding")]
impl Location {
pub fn as_str(&self) -> &str {
self.0
}
pub fn for_number(number: &PhoneNumber) -> Option<Self> {
LOCATIONS
.longest_number(number.calling_code().value(), number.national_number())
.map(Self)
}
}
#[cfg(feature = "geocoding")]
impl AsRef<str> for Location {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[cfg(feature = "carrier")]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct CarrierName(&'static str);
#[cfg(feature = "carrier")]
impl CarrierName {
pub fn as_str(&self) -> &str {
self.0
}
pub fn for_number(number: &PhoneNumber) -> Option<Self> {
CARRIER_NAMES
.longest_number(number.calling_code().value(), number.national_number())
.map(Self)
}
}
#[cfg(feature = "carrier")]
impl AsRef<str> for CarrierName {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[cfg(feature = "timezone")]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct TimeZones(&'static str);
#[cfg(feature = "timezone")]
impl TimeZones {
pub fn iter(&self) -> impl Iterator<Item = &str> {
self.0.split('&')
}
pub fn for_number(number: &PhoneNumber) -> Option<Self> {
TIME_ZONES
.longest_number(number.calling_code().value(), number.national_number())
.map(Self)
}
}
#[cfg(feature = "timezone")]
impl<'a> IntoIterator for &'a TimeZones {
type Item = &'a str;
type IntoIter = core::str::Split<'a, char>;
fn into_iter(self) -> Self::IntoIter {
self.0.split('&')
}
}