Struct IanaParser

Source
pub struct IanaParser { /* private fields */ }
Expand description

A parser for parsing an IANA time zone ID to a TimeZone type.

There are approximately 600 IANA identifiers and 450 TimeZone identifiers. These lists grow very slowly; in a typical year, 2-3 new identifiers are added.

This means that multiple IANA identifiers map to the same TimeZone. For example, the following four IANA identifiers all map to the same TimeZone:

  • America/Fort_Wayne
  • America/Indiana/Indianapolis
  • America/Indianapolis
  • US/East-Indiana

For each TimeZone, there is one “canonical” IANA time zone ID (for the above example, it is America/Indiana/Indianapolis). Note that the canonical identifier can change over time. For example, the identifier Europe/Kiev was renamed to the newly-added identifier Europe/Kyiv in 2022.

§Examples

use icu::locale::subtags::subtag;
use icu::time::zone::IanaParser;
use icu::time::TimeZone;

let parser = IanaParser::new();

// The IANA zone "Australia/Melbourne" is the BCP-47 zone "aumel":
assert_eq!(
    parser.parse("Australia/Melbourne"),
    TimeZone(subtag!("aumel"))
);

// Parsing is ASCII-case-insensitive:
assert_eq!(
    parser.parse("australia/melbourne"),
    TimeZone(subtag!("aumel"))
);

// The IANA zone "Australia/Victoria" is an alias:
assert_eq!(
    parser.parse("Australia/Victoria"),
    TimeZone(subtag!("aumel"))
);

// The IANA zone "Australia/Boing_Boing" does not exist
// (maybe not *yet*), so it produces the special unknown
// time zone in order for this operation to be infallible:
assert_eq!(parser.parse("Australia/Boing_Boing"), TimeZone::UNKNOWN);

Implementations§

Source§

impl IanaParser

Source

pub fn new() -> IanaParserBorrowed<'static>

Creates a new IanaParser using compiled data.

See IanaParser for an example.

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

Source

pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), ) -> Result<IanaParser, DataError>

A version of [Self :: new] that uses custom data provided by a BufferProvider.

Enabled with the serde feature.

📚 Help choosing a constructor

Source

pub fn try_new_unstable<P>(provider: &P) -> Result<IanaParser, DataError>

A version of Self::new that uses custom data provided by a DataProvider.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.
Source

pub fn as_borrowed(&self) -> IanaParserBorrowed<'_>

Returns a borrowed version of the parser that can be queried.

This avoids a small potential indirection cost when querying the parser.

Trait Implementations§

Source§

impl AsRef<IanaParser> for IanaParser

Source§

fn as_ref(&self) -> &IanaParser

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for IanaParser

Source§

fn clone(&self) -> IanaParser

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 Debug for IanaParser

Source§

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

Formats the value using the given formatter. Read more

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.
Source§

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