Struct icu_timezone::TimeZoneIdMapperBorrowed
source · pub struct TimeZoneIdMapperBorrowed<'a> {
data: &'a IanaToBcp47MapV2<'a>,
}
Expand description
A borrowed wrapper around the time zone ID mapper, returned by
TimeZoneIdMapper::as_borrowed()
. More efficient to query.
Fields§
§data: &'a IanaToBcp47MapV2<'a>
Implementations§
source§impl<'a> TimeZoneIdMapperBorrowed<'a>
impl<'a> TimeZoneIdMapperBorrowed<'a>
sourcepub fn iana_to_bcp47(&self, iana_id: &str) -> Option<TimeZoneBcp47Id>
pub fn iana_to_bcp47(&self, iana_id: &str) -> Option<TimeZoneBcp47Id>
Gets the BCP-47 time zone ID from an IANA time zone ID with a case-insensitive lookup.
Returns None
if the IANA ID is not found.
§Examples
use icu_timezone::TimeZoneBcp47Id;
use icu_timezone::TimeZoneIdMapper;
let mapper = TimeZoneIdMapper::new();
let mapper = mapper.as_borrowed();
let result = mapper.iana_to_bcp47("Asia/CALCUTTA").unwrap();
assert_eq!(*result, "inccu");
// Unknown IANA time zone ID:
assert_eq!(mapper.iana_to_bcp47("America/San_Francisco"), None);
sourcepub fn iana_bytes_to_bcp47(&self, iana_id: &[u8]) -> Option<TimeZoneBcp47Id>
pub fn iana_bytes_to_bcp47(&self, iana_id: &[u8]) -> Option<TimeZoneBcp47Id>
Same as Self::iana_to_bcp47()
but works with potentially ill-formed UTF-8.
sourcepub fn normalize_iana<'s>(
&self,
iana_id: &'s str,
) -> Option<(Cow<'s, str>, TimeZoneBcp47Id)>
pub fn normalize_iana<'s>( &self, iana_id: &'s str, ) -> Option<(Cow<'s, str>, TimeZoneBcp47Id)>
Normalizes the syntax of an IANA time zone ID.
Also returns the BCP-47 time zone ID.
Returns None
if the IANA ID is not found.
§Examples
use icu_timezone::TimeZoneBcp47Id;
use icu_timezone::TimeZoneIdMapper;
use std::borrow::Cow;
let mapper = TimeZoneIdMapper::new();
let mapper = mapper.as_borrowed();
let result = mapper.normalize_iana("Asia/CALCUTTA").unwrap();
assert_eq!(result.0, "Asia/Calcutta");
assert!(matches!(result.0, Cow::Owned(_)));
assert_eq!(*result.1, "inccu");
// Borrows when able:
let result = mapper.normalize_iana("America/Chicago").unwrap();
assert_eq!(result.0, "America/Chicago");
assert!(matches!(result.0, Cow::Borrowed(_)));
// Unknown IANA time zone ID:
assert_eq!(mapper.normalize_iana("America/San_Francisco"), None);
sourcepub fn canonicalize_iana<'s>(
&self,
iana_id: &'s str,
) -> Option<(Cow<'s, str>, TimeZoneBcp47Id)>
pub fn canonicalize_iana<'s>( &self, iana_id: &'s str, ) -> Option<(Cow<'s, str>, TimeZoneBcp47Id)>
Returns the canonical, normalized identifier of the given IANA time zone.
Also returns the BCP-47 time zone ID.
Returns None
if the IANA ID is not found.
§Examples
use icu_timezone::TimeZoneBcp47Id;
use icu_timezone::TimeZoneIdMapper;
use std::borrow::Cow;
let mapper = TimeZoneIdMapper::new();
let mapper = mapper.as_borrowed();
let result = mapper.canonicalize_iana("Asia/CALCUTTA").unwrap();
assert_eq!(result.0, "Asia/Kolkata");
assert!(matches!(result.0, Cow::Owned(_)));
assert_eq!(*result.1, "inccu");
// Borrows when able:
let result = mapper.canonicalize_iana("America/Chicago").unwrap();
assert_eq!(result.0, "America/Chicago");
assert!(matches!(result.0, Cow::Borrowed(_)));
// Unknown IANA time zone ID:
assert_eq!(mapper.canonicalize_iana("America/San_Francisco"), None);
sourcepub fn find_canonical_iana_from_bcp47(
&self,
bcp47_id: TimeZoneBcp47Id,
) -> Option<String>
pub fn find_canonical_iana_from_bcp47( &self, bcp47_id: TimeZoneBcp47Id, ) -> Option<String>
Returns the canonical, normalized IANA ID of the given BCP-47 ID.
This function performs a linear search over all IANA IDs. If this is problematic, consider one of the following functions instead:
TimeZoneIdMapperBorrowed::canonicalize_iana()
is faster if you have an IANA ID.TimeZoneIdMapperWithFastCanonicalizationBorrowed::canonical_iana_from_bcp47()
is faster, but it requires loading additional data (seeTimeZoneIdMapperWithFastCanonicalization
).
Returns None
if the BCP-47 ID is not found.
§Examples
use icu_timezone::TimeZoneBcp47Id;
use icu_timezone::TimeZoneIdMapper;
use std::borrow::Cow;
use tinystr::tinystr;
let mapper = TimeZoneIdMapper::new();
let mapper = mapper.as_borrowed();
let bcp47_id = TimeZoneBcp47Id(tinystr!(8, "inccu"));
let result = mapper.find_canonical_iana_from_bcp47(bcp47_id).unwrap();
assert_eq!(result, "Asia/Kolkata");
// Unknown BCP-47 time zone ID:
let bcp47_id = TimeZoneBcp47Id(tinystr!(8, "ussfo"));
assert_eq!(mapper.find_canonical_iana_from_bcp47(bcp47_id), None);
sourcefn iana_lookup_quick(&self, iana_id: impl AsRef<[u8]>) -> Option<IanaTrieValue>
fn iana_lookup_quick(&self, iana_id: impl AsRef<[u8]>) -> Option<IanaTrieValue>
Queries the data for iana_id
without recording the normalized string.
This is a fast, no-alloc lookup.
sourcefn iana_lookup_with_normalization<'l, 's>(
&'l self,
iana_id: &'s str,
cursor_fn: impl FnMut(&ZeroAsciiIgnoreCaseTrieCursor<'l>),
) -> Option<(IanaTrieValue, Cow<'s, str>)>
fn iana_lookup_with_normalization<'l, 's>( &'l self, iana_id: &'s str, cursor_fn: impl FnMut(&ZeroAsciiIgnoreCaseTrieCursor<'l>), ) -> Option<(IanaTrieValue, Cow<'s, str>)>
Queries the data for iana_id
while keeping track of the normalized string.
This is a fast lookup, but it may require allocating memory.
sourcefn iana_search(
&self,
needle: IanaTrieValue,
string: String,
stack: Vec<(ZeroAsciiIgnoreCaseTrieCursor<'_>, usize, usize)>,
) -> Option<String>
fn iana_search( &self, needle: IanaTrieValue, string: String, stack: Vec<(ZeroAsciiIgnoreCaseTrieCursor<'_>, usize, usize)>, ) -> Option<String>
Performs a reverse lookup by walking the trie with an optional start position. This is not a fast operation since it requires a linear search.
Trait Implementations§
source§impl<'a> Clone for TimeZoneIdMapperBorrowed<'a>
impl<'a> Clone for TimeZoneIdMapperBorrowed<'a>
source§fn clone(&self) -> TimeZoneIdMapperBorrowed<'a>
fn clone(&self) -> TimeZoneIdMapperBorrowed<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for TimeZoneIdMapperBorrowed<'a>
impl<'a> Debug for TimeZoneIdMapperBorrowed<'a>
impl<'a> Copy for TimeZoneIdMapperBorrowed<'a>
Auto Trait Implementations§
impl<'a> Freeze for TimeZoneIdMapperBorrowed<'a>
impl<'a> RefUnwindSafe for TimeZoneIdMapperBorrowed<'a>
impl<'a> Send for TimeZoneIdMapperBorrowed<'a>
impl<'a> Sync for TimeZoneIdMapperBorrowed<'a>
impl<'a> Unpin for TimeZoneIdMapperBorrowed<'a>
impl<'a> UnwindSafe for TimeZoneIdMapperBorrowed<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)