Struct icu_timezone::IanaBcp47RoundTripMapper
source · pub struct IanaBcp47RoundTripMapper { /* private fields */ }
Expand description
A mapper that supports mapping IANA identifiers to BCP-47 identifiers and also the other way around.
This is mainly useful if the IANA identifier needs to be recovered or canonicalized.
Examples
Demonstration of canonicalization of the time zone identifier:
use icu::timezone::IanaBcp47RoundTripMapper;
let mapper = IanaBcp47RoundTripMapper::new();
let mapper_borrowed = mapper.as_borrowed();
// Look up the time zone ID for "Asia/Calcutta"
let bcp47_id = mapper_borrowed.iana_to_bcp47("Asia/Calcutta");
assert_eq!(bcp47_id, Some("inccu".parse().unwrap()));
// Get it back as the canonical form "Asia/Kolkata"
let iana_id = mapper_borrowed.bcp47_to_iana(bcp47_id.unwrap());
assert_eq!(iana_id, Some("Asia/Kolkata"))
Implementations§
source§impl IanaBcp47RoundTripMapper
impl IanaBcp47RoundTripMapper
sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a new IanaBcp47RoundTripMapper
using compiled data.
See IanaBcp47RoundTripMapper
for an example.
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized)
) -> Result<Self, TimeZoneError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized) ) -> Result<Self, TimeZoneError>
A version of Self::new
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized)
) -> Result<Self, TimeZoneError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized) ) -> Result<Self, TimeZoneError>
A version of Self::new
that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, TimeZoneError>where
P: DataProvider<IanaToBcp47MapV1Marker> + DataProvider<Bcp47ToIanaMapV1Marker> + ?Sized,
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, TimeZoneError>where P: DataProvider<IanaToBcp47MapV1Marker> + DataProvider<Bcp47ToIanaMapV1Marker> + ?Sized,
A version of Self::new
that uses custom data provided by a DataProvider
.
sourcepub fn as_borrowed(&self) -> IanaBcp47RoundTripMapperBorrowed<'_>
pub fn as_borrowed(&self) -> IanaBcp47RoundTripMapperBorrowed<'_>
Returns a borrowed version of the mapper that can be queried.
This avoids a small potential cost of reading the data pointer.