Struct Extensions

struct Extensions { ... }

A map of extensions associated with a given Locale.

Fields

unicode: Unicode

A representation of the data for a Unicode extension, when present in the locale identifier.

transform: Transform

A representation of the data for a transform extension, when present in the locale identifier.

private: Private

A representation of the data for a private-use extension, when present in the locale identifier.

other: &'static [Other]

A sequence of any other extensions that are present in the locale identifier but are not formally defined and represented explicitly as Unicode, Transform, and Private are.

Implementations

impl Extensions

const fn new() -> Self

Returns a new empty map of extensions. Same as default(), but is const.

Examples

use icu::locale::extensions::Extensions;

assert_eq!(Extensions::new(), Extensions::default());
const fn from_unicode(unicode: Unicode) -> Self

Function to create a new map of extensions containing exactly one unicode extension, callable in const context.

fn is_empty(self: &Self) -> bool

Returns whether there are no extensions present.

Examples

use icu::locale::Locale;

let loc: Locale = "en-US-u-foo".parse().expect("Parsing failed.");

assert!(!loc.extensions.is_empty());
fn total_cmp(self: &Self, other: &Self) -> Ordering

Returns an ordering suitable for use in BTreeSet.

The ordering may or may not be equivalent to string ordering, and it may or may not be stable across ICU4X releases.

fn retain_by_type<F>(self: &mut Self, predicate: F)
where
    F: FnMut(ExtensionType) -> bool

Retains the specified extension types, clearing all others.

Examples

use icu::locale::extensions::ExtensionType;
use icu::locale::Locale;

let loc: Locale =
    "und-a-hello-t-mul-u-world-z-zzz-x-extra".parse().unwrap();

let mut only_unicode = loc.clone();
only_unicode
    .extensions
    .retain_by_type(|t| t == ExtensionType::Unicode);
assert_eq!(only_unicode, "und-u-world".parse().unwrap());

let mut only_t_z = loc.clone();
only_t_z.extensions.retain_by_type(|t| {
    t == ExtensionType::Transform || t == ExtensionType::Other(b'z')
});
assert_eq!(only_t_z, "und-t-mul-z-zzz".parse().unwrap());

impl Clone for Extensions

fn clone(self: &Self) -> Extensions

impl Debug for Extensions

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

impl Default for Extensions

fn default() -> Extensions

impl Eq for Extensions

impl Freeze for Extensions

impl Hash for Extensions

fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)

impl PartialEq for Extensions

fn eq(self: &Self, other: &Extensions) -> bool

impl RefUnwindSafe for Extensions

impl Send for Extensions

impl StructuralPartialEq for Extensions

impl Sync for Extensions

impl Unpin for Extensions

impl UnsafeUnpin for Extensions

impl UnwindSafe for Extensions

impl<T> Any for Extensions

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Extensions

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Extensions

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Extensions

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

impl<T> ErasedDestructor for Extensions

impl<T> From for Extensions

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for Extensions

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for Extensions

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Extensions

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

impl<T, U> TryInto for Extensions

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>