pub struct IanaParserExtendedBorrowed<'a> { /* private fields */ }Expand description
A borrowed wrapper around the time zone ID parser, returned by
IanaParserExtended::as_borrowed(). More efficient to query.
Implementations§
Source§impl IanaParserExtendedBorrowed<'static>
 
impl IanaParserExtendedBorrowed<'static>
Sourcepub fn new() -> IanaParserExtendedBorrowed<'static>
 
pub fn new() -> IanaParserExtendedBorrowed<'static>
Creates a new IanaParserExtendedBorrowed using compiled data.
See IanaParserExtendedBorrowed for an example.
✨ Enabled with the compiled_data Cargo feature.
Sourcepub fn static_to_owned(&self) -> IanaParserExtended<IanaParser>
 
pub fn static_to_owned(&self) -> IanaParserExtended<IanaParser>
Cheaply converts a [IanaParserExtendedBorrowed<'static>] into a IanaParserExtended.
Note: Due to branching and indirection, using IanaParserExtended might inhibit some
compile-time optimizations that are possible with IanaParserExtendedBorrowed.
Source§impl<'a> IanaParserExtendedBorrowed<'a>
 
impl<'a> IanaParserExtendedBorrowed<'a>
Sourcepub fn parse(&self, iana_id: &str) -> TimeZoneAndCanonicalAndNormalized<'a>
 
pub fn parse(&self, iana_id: &str) -> TimeZoneAndCanonicalAndNormalized<'a>
Gets the TimeZone, the canonical IANA ID, and the case-normalized IANA ID from a case-insensitive IANA time zone ID.
Returns TimeZone::UNKNOWN / "Etc/Unknown" if the IANA ID is not found.
§Examples
use icu_time::zone::iana::IanaParserExtended;
use icu_time::TimeZone;
let parser = IanaParserExtended::new();
let r = parser.parse("Asia/CALCUTTA");
assert_eq!(r.time_zone.as_str(), "inccu");
assert_eq!(r.canonical, "Asia/Kolkata");
assert_eq!(r.normalized, "Asia/Calcutta");
// Unknown IANA time zone ID:
let r = parser.parse("America/San_Francisco");
assert_eq!(r.time_zone, TimeZone::UNKNOWN);
assert_eq!(r.canonical, "Etc/Unknown");
assert_eq!(r.normalized, "Etc/Unknown");Sourcepub fn parse_from_utf8(
    &self,
    iana_id: &[u8],
) -> TimeZoneAndCanonicalAndNormalized<'a>
 
pub fn parse_from_utf8( &self, iana_id: &[u8], ) -> TimeZoneAndCanonicalAndNormalized<'a>
Same as Self::parse() but works with potentially ill-formed UTF-8.
Sourcepub fn iter(&self) -> TimeZoneAndCanonicalIter<'a> ⓘ
 
pub fn iter(&self) -> TimeZoneAndCanonicalIter<'a> ⓘ
Returns an iterator over all time zones and their canonical IANA identifiers.
The iterator is sorted by the canonical IANA identifiers.
§Examples
use icu::locale::subtags::subtag;
use icu::time::zone::iana::IanaParserExtended;
use icu::time::zone::TimeZone;
use std::collections::BTreeSet;
let parser = IanaParserExtended::new();
let ids = parser
    .iter()
    .map(|t| (t.time_zone, t.canonical))
    .collect::<BTreeSet<_>>();
assert!(ids.contains(&(TimeZone(subtag!("uaiev")), "Europe/Kyiv")));
assert!(parser.iter().count() >= 445);Sourcepub fn iter_all(&self) -> TimeZoneAndCanonicalAndNormalizedIter<'a> ⓘ
 
pub fn iter_all(&self) -> TimeZoneAndCanonicalAndNormalizedIter<'a> ⓘ
Returns an iterator equivalent to calling Self::parse on all IANA time zone identifiers.
The only guarantee w.r.t iteration order is that for a given time zone, the canonical IANA identifier will come first, and the following non-canonical IANA identifiers will be sorted. However, the output is not grouped by time zone.
The current implementation returns all sorted canonical IANA identifiers first, followed by all sorted non-canonical identifiers, however this is subject to change.
§Examples
use icu::time::zone::iana::IanaParserExtended;
use icu::time::zone::TimeZone;
use std::collections::BTreeMap;
use icu::locale::subtags::subtag;
let parser = IanaParserExtended::new();
let ids = parser.iter_all().enumerate().map(|(a, b)| ((b.time_zone, b.canonical, b.normalized), a)).collect::<std::collections::BTreeMap<_, _>>();
let kyiv_idx = ids[&(TimeZone(subtag!("uaiev")), "Europe/Kyiv", "Europe/Kyiv")];
let kiev_idx = ids[&(TimeZone(subtag!("uaiev")), "Europe/Kyiv", "Europe/Kiev")];
let uzgh_idx = ids[&(TimeZone(subtag!("uaiev")), "Europe/Kyiv", "Europe/Uzhgorod")];
let zapo_idx = ids[&(TimeZone(subtag!("uaiev")), "Europe/Kyiv", "Europe/Zaporozhye")];
// The order for a particular time zone is guaranteed
assert!(kyiv_idx < kiev_idx && kiev_idx < uzgh_idx && uzgh_idx < zapo_idx);
// It is not guaranteed that the entries for a particular time zone are consecutive
assert!(kyiv_idx + 1 != kiev_idx);
assert!(parser.iter_all().count() >= 598);Trait Implementations§
Source§impl<'a> Clone for IanaParserExtendedBorrowed<'a>
 
impl<'a> Clone for IanaParserExtendedBorrowed<'a>
Source§fn clone(&self) -> IanaParserExtendedBorrowed<'a>
 
fn clone(&self) -> IanaParserExtendedBorrowed<'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 IanaParserExtendedBorrowed<'a>
 
impl<'a> Debug for IanaParserExtendedBorrowed<'a>
Source§impl Default for IanaParserExtendedBorrowed<'static>
 
impl Default for IanaParserExtendedBorrowed<'static>
Source§fn default() -> IanaParserExtendedBorrowed<'static>
 
fn default() -> IanaParserExtendedBorrowed<'static>
impl<'a> Copy for IanaParserExtendedBorrowed<'a>
Auto Trait Implementations§
impl<'a> Freeze for IanaParserExtendedBorrowed<'a>
impl<'a> RefUnwindSafe for IanaParserExtendedBorrowed<'a>
impl<'a> Send for IanaParserExtendedBorrowed<'a>
impl<'a> Sync for IanaParserExtendedBorrowed<'a>
impl<'a> Unpin for IanaParserExtendedBorrowed<'a>
impl<'a> UnwindSafe for IanaParserExtendedBorrowed<'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§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more