Struct LanguagesDetect

Source
#[non_exhaustive]
pub struct LanguagesDetect<'names> { pub env: Option<HashMap<String, String>>, pub names: Option<&'names [&'names str]>, }
Expand description

Determine preferred languages as per the current locale settings.

This class is used to invoke the get_preferred_languages() function with reasonable default values: the current process environment and the default LOCALE_VARIABLES list of variable names, with the option of overriding either.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§env: Option<HashMap<String, String>>

The environment variables to examine instead of std::env.

§names: Option<&'names [&'names str]>

The names of locale variables to use instead of the defaults.

Implementations§

Source§

impl<'names> LanguagesDetect<'names>

Source

pub fn new() -> Self

Prepare to detect languages in the default manner.

Source

pub fn detect(self) -> Result<Vec<String>, UErr>

Detect the preferred languages according to the specified settings.

§Errors

Returns an error if one of the required environment variables has a value that is not a valid UTF-8 string.

Source

pub fn with_env(self, env: HashMap<String, String>) -> Self

Specify the environment variables to examine instead of std::env.

Source

pub fn with_names(self, names: &'names [&'names str]) -> Self

Specify the names of the environment variables to look at instead of LOCALE_VARIABLES.

Trait Implementations§

Source§

impl<'names> Debug for LanguagesDetect<'names>

Source§

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

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

impl<'names> Default for LanguagesDetect<'names>

Source§

fn default() -> LanguagesDetect<'names>

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

Auto Trait Implementations§

§

impl<'names> Freeze for LanguagesDetect<'names>

§

impl<'names> RefUnwindSafe for LanguagesDetect<'names>

§

impl<'names> Send for LanguagesDetect<'names>

§

impl<'names> Sync for LanguagesDetect<'names>

§

impl<'names> Unpin for LanguagesDetect<'names>

§

impl<'names> UnwindSafe for LanguagesDetect<'names>

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

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.