Skip to main content

Locale

Trait Locale 

Source
pub trait Locale:
    Segment
    + Serialize
    + Copy
    + Eq
    + 'static {
    type Text<T>;

    const ALL: &'static [Self];

    // Required method
    fn pick<T>(self, text: Self::Text<T>) -> T;

    // Provided method
    fn tag(self) -> String { ... }
}
Expand description

The locales of an application: an enum with #[derive(Segment)] whose segments are BCP 47 tags.

The compiler checks that each text has every locale, through Locale::Text, and that Locale::pick handles every locale, through its match. It does not check that Locale::ALL lists every variant; a variant left out of it is never chosen by negotiate.

Required Associated Constants§

Source

const ALL: &'static [Self]

Every locale the application serves, the default first.

Required Associated Types§

Source

type Text<T>

One value per locale, usually a struct with a field per locale.

Required Methods§

Source

fn pick<T>(self, text: Self::Text<T>) -> T

The value of text for this locale.

Provided Methods§

Source

fn tag(self) -> String

The BCP 47 tag of this locale, the string serde writes for it.

§Panics

Panics if serde does not write the locale as a string, which an enum with #[derive(Segment)] always does.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§