[][src]Struct locale_config::LanguageRange

pub struct LanguageRange<'a> { /* fields omitted */ }

Language and culture identifier.

This object holds a RFC4647 extended language range.

The internal data may be owned or shared from object with lifetime 'a. The lifetime can be extended using the into_static() method, which internally clones the data as needed.

Syntax

The range is composed of --separated alphanumeric subtags, possibly replaced by *s. It might be empty.

In agreement with RFC4647, this object only requires that the tag matches:

language_tag = (alpha{1,8} | "*")
               ("-" (alphanum{1,8} | "*"))*

The exact interpretation is up to the downstream localization provider, but it expected that it will be matched against a normalized RFC5646 language tag, which has the structure:

language_tag    = language
                  ("-" script)?
                  ("-" region)?
                  ("-" variant)*
                  ("-" extension)*
                  ("-" private)?

language        = alpha{2,3} ("-" alpha{3}){0,3}

script          = aplha{4}

region          = alpha{2}
                | digit{3}

variant         = alphanum{5,8}
                | digit alphanum{3}

extension       = [0-9a-wyz] ("-" alphanum{2,8})+

private         = "x" ("-" alphanum{1,8})+

The values obtained by inspecting the system are normalized according to those rules.

The content will be case-normalized as recommended in RFC5646 §2.1.1, namely:

When detecting system configuration, additional options that may be generated under the -u- extension currently are:

And under the -x- extension, following options are defined:

Methods

impl<'a> LanguageRange<'a>[src]

pub fn new(lt: &'a str) -> Result<LanguageRange, Error>[src]

Construct LanguageRange from string, with normalization.

LanguageRange must follow the RFC4647 syntax. It will be case-normalized as recommended in RFC5646 §2.1.1, namely:

  • language, if recognized, is written in lowercase,
  • script, if recognized, is written with first capital,
  • country, if recognized, is written in uppercase and
  • all other subtags are written in lowercase.

pub fn invariant() -> LanguageRange<'static>[src]

Return LanguageRange for the invariant locale.

Invariant language is identified simply by empty string.

pub fn into_static(self) -> LanguageRange<'static>[src]

Clone the internal data to extend lifetime.

pub fn to_shared(&'a self) -> Self[src]

Create new instance sharing the internal data.

pub fn from_unix(s: &str) -> Result<LanguageRange<'static>, Error>[src]

Create language tag from Unix/Linux/GNU locale tag.

Unix locale tags have the form

language [ _ region ] [ . encoding ] [ @ variant ]

The language and region have the same format as RFC5646. Encoding is not relevant here, since Rust always uses Utf-8. That leaves variant, which is unfortunately rather free-form. So this function will translate known variants to corresponding RFC5646 subtags and represent anything else with Unicode POSIX variant (-u-va-) extension.

Note: This function is public here for benefit of applications that may come across this kind of tags from other sources than system configuration.

Trait Implementations

impl<'a> Clone for LanguageRange<'a>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> From<LanguageRange<'a>> for Locale[src]

impl<'a> Eq for LanguageRange<'a>[src]

impl<'a> PartialEq<LanguageRange<'a>> for LanguageRange<'a>[src]

impl<'a> AsRef<str> for LanguageRange<'a>[src]

impl<'a> Debug for LanguageRange<'a>[src]

impl<'a> Display for LanguageRange<'a>[src]

impl<'a> Hash for LanguageRange<'a>[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

Auto Trait Implementations

impl<'a> Send for LanguageRange<'a>

impl<'a> Sync for LanguageRange<'a>

Blanket Implementations

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]