Skip to main content

LocaleState

Struct LocaleState 

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

A language and the locale keys a lookup tries for it.

The global language set by set_lang is one of these (see get_lang), and servers that render for several users at once can build one per user (or request) and pass it to t_in!.

Building one resolves the fallback chain once (a few small allocations), so every lookup afterwards just walks a short precomputed slice of keys.

Implementations§

Source§

impl LocaleState

Source

pub fn new(id: LanguageIdentifier) -> Self

Resolves the fallback chain for id.

Source

pub fn id(&self) -> &LanguageIdentifier

The language identifier this state was built from (for the global language, the one passed to set_lang; en-US by default).

Source

pub fn key(&self) -> &str

The canonical string form of id (e.g. "en-US"), which is the first key the generated caches are probed with.

Source

pub fn chain(&self) -> impl ExactSizeIterator<Item = &str>

The locale keys a lookup tries, most specific first, before the catalog’s fallback locale.

Trait Implementations§

Source§

impl Debug for LocaleState

Source§

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

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

impl From<LanguageIdentifier> for LocaleState

Source§

fn from(id: LanguageIdentifier) -> Self

Converts to this type from the input type.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.