Struct unic_locale::extensions::TransformExtensionList

source ·
pub struct TransformExtensionList { /* private fields */ }
Expand description

A list of Unicode BCP47 T Extensions as defined in Unicode Locale Identifier specification.

Transform extension carries information about source language or script of transformed content, including content that has been transliterated, transcribed, or translated, or in some other way influenced by the source (See RFC 6497 for details).

§Examples

use unic_locale_impl::{Locale, LanguageIdentifier};

let mut loc: Locale = "de-t-en-US-h0-hybrid".parse()
    .expect("Parsing failed.");

let en_us: LanguageIdentifier = "en-US".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tlang(), Some(&en_us));
assert_eq!(
    loc.extensions.transform.tfield("h0")
                            .expect("Getting tfield failed.")
                            .collect::<Vec<_>>(),
    &["hybrid"]
);

Implementations§

source§

impl TransformExtensionList

source

pub fn is_empty(&self) -> bool

Returns true if there are no tfields and no tlang in the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.is_empty(), false);
source

pub fn tlang(&self) -> Option<&LanguageIdentifier>

Gets tlang from the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

let tlang: LanguageIdentifier = "es-AR".parse()
    .expect("Parsing failed on tlang.");

assert_eq!(loc.extensions.transform.tlang(), Some(&tlang));
source

pub fn set_tlang( &mut self, tlang: LanguageIdentifier ) -> Result<(), LocaleError>

Sets tlang on the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

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

let tlang: LanguageIdentifier = "es-AR".parse()
    .expect("Parsing failed on tlang.");

loc.extensions.transform.set_tlang(tlang)
    .expect("Setting tlang failed.");

assert_eq!(loc.to_string(), "en-US-t-es-AR");
source

pub fn clear_tlang(&mut self)

Clears tlang on the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;
use unic_langid_impl::LanguageIdentifier;

let mut loc: Locale = "en-US-t-es-AR".parse()
    .expect("Parsing failed.");

loc.extensions.transform.clear_tlang();

assert_eq!(loc.to_string(), "en-US");
source

pub fn tfield<S>(&self, tkey: S) -> Result<impl ExactSizeIterator, LocaleError>
where S: AsRef<[u8]>,

Returns the tvalue of tfield in the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tfield("k0")
               .expect("Getting tfield failed.")
               .collect::<Vec<_>>(),
           &["dvorak"]);

// Here tfield with tkey "m0" is not available
assert_eq!(loc.extensions.transform.tfield("m0")
               .expect("Getting tfield failed.")
               .collect::<Vec<_>>()
               .is_empty(),
           true);
source

pub fn tfield_keys(&self) -> impl ExactSizeIterator

Returns an iterator over all tkeys in the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak-h0-hybrid".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.tfield_keys().collect::<Vec<_>>(),
           &["h0", "k0"]);
source

pub fn set_tfield<S>( &mut self, tkey: S, tvalue: &[S] ) -> Result<(), LocaleError>
where S: AsRef<[u8]>,

Adds a tfield to the TransformExtensionList or sets tvalue for tkey if tfield is already included in the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;

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

loc.extensions.transform.set_tfield("k0", &["dvorak"])
    .expect("Setting tfield failed.");

assert_eq!(loc.to_string(), "en-US-t-k0-dvorak");

loc.extensions.transform.set_tfield("k0", &["colemak"])
    .expect("Setting tfield failed.");

assert_eq!(loc.to_string(), "en-US-t-k0-colemak");
source

pub fn remove_tfield<S>(&mut self, tkey: S) -> Result<bool, LocaleError>
where S: AsRef<[u8]>,

Removes a tfield from the TransformExtensionList.

Returns true if tfield was included in the TransformExtensionList before removal.

§Examples
use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

assert_eq!(loc.extensions.transform.remove_tfield("k0")
               .expect("Removing tfield failed."),
           true);

assert_eq!(loc.to_string(), "en-US");
source

pub fn clear_tfields(&mut self)

Clears all tfields from the TransformExtensionList.

§Examples
use unic_locale_impl::Locale;

let mut loc: Locale = "en-US-t-k0-dvorak".parse()
    .expect("Parsing failed.");

loc.extensions.transform.clear_tfields();
assert_eq!(loc.to_string(), "en-US");

Trait Implementations§

source§

impl Clone for TransformExtensionList

source§

fn clone(&self) -> TransformExtensionList

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 TransformExtensionList

source§

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

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

impl Default for TransformExtensionList

source§

fn default() -> TransformExtensionList

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

impl Display for TransformExtensionList

source§

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

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

impl Hash for TransformExtensionList

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for TransformExtensionList

source§

fn cmp(&self, other: &TransformExtensionList) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for TransformExtensionList

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for TransformExtensionList

source§

fn partial_cmp(&self, other: &TransformExtensionList) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for TransformExtensionList

source§

impl StructuralPartialEq for TransformExtensionList

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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.