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() -> Self
pub fn new() -> Self
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) -> (TimeZone, &'a str, &'a str)
pub fn parse(&self, iana_id: &str) -> (TimeZone, &'a str, &'a str)
Gets the time zone, the canonical IANA ID, and the normalized IANA ID from an IANA time zone ID.
Returns [(TimeZone::unknown(), "Etc/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 (tz, canonical, normalized) = parser.parse("Asia/CALCUTTA");
assert_eq!(*tz, "inccu");
assert_eq!(canonical, "Asia/Kolkata");
assert_eq!(normalized, "Asia/Calcutta");
// Unknown IANA time zone ID:
assert_eq!(
parser.parse("America/San_Francisco"),
(TimeZone::unknown(), "Etc/Unknown", "Etc/Unknown".into())
);
Sourcepub fn parse_from_utf8(&self, iana_id: &[u8]) -> (TimeZone, &'a str, &'a str)
pub fn parse_from_utf8(&self, iana_id: &[u8]) -> (TimeZone, &'a str, &'a str)
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::time::zone::iana::IanaParserExtended;
use icu::time::zone::TimeZone;
use std::collections::BTreeSet;
use tinystr::tinystr;
let parser = IanaParserExtended::new();
let ids = parser.iter().collect::<BTreeSet<_>>();
assert!(ids.contains(&(TimeZone(tinystr!(8, "uaiev")), "Europe/Kyiv")));
assert_eq!(ids.len(), 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 tinystr::tinystr;
let parser = IanaParserExtended::new();
let ids = parser.iter_all().enumerate().map(|(a, b)| (b, a)).collect::<std::collections::BTreeMap<_, _>>();
let kyiv_idx = ids[&(TimeZone(tinystr!(8, "uaiev")), "Europe/Kyiv", "Europe/Kyiv")];
let kiev_idx = ids[&(TimeZone(tinystr!(8, "uaiev")), "Europe/Kyiv", "Europe/Kiev")];
let uzgh_idx = ids[&(TimeZone(tinystr!(8, "uaiev")), "Europe/Kyiv", "Europe/Uzhgorod")];
let zapo_idx = ids[&(TimeZone(tinystr!(8, "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_eq!(ids.len(), 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>
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