icu_time::zone::iana

Struct IanaParserExtendedBorrowed

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

Source

pub fn new() -> Self

Creates a new IanaParserExtendedBorrowed using compiled data.

See IanaParserExtendedBorrowed for an example.

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

Source

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>

Source

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

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.

Source

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

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>

Source§

fn clone(&self) -> IanaParserExtendedBorrowed<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for IanaParserExtendedBorrowed<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IanaParserExtendedBorrowed<'static>

Source§

fn default() -> Self

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

impl<'a> Copy for IanaParserExtendedBorrowed<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> ErasedDestructor for T
where T: 'static,