Skip to main content

Locale

Struct Locale 

Source
#[non_exhaustive]
pub struct Locale {
Show 15 fields pub tag: String, pub decimal_mark: String, pub big_mark: String, pub min_grouping_digits: usize, pub currency_symbol: String, pub currency_position: CurrencyPosition, pub currency_spacing: String, pub percent_suffix: String, pub months_short: [String; 12], pub months_long: [String; 12], pub days_short: [String; 7], pub days_long: [String; 7], pub date_format: String, pub month_format: String, pub time_format: String,
}
Expand description

Number and date formatting conventions of a locale.

Construct one with a preset (en_us, de_de, fr_fr, en_gb) or from_tag, then adjust the public fields or use the with_* builders. The struct is #[non_exhaustive] so new conventions can be added without a breaking change.

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.
§tag: String

Canonical BCP-47 tag of the preset, e.g. "de-DE".

§decimal_mark: String

Decimal mark ("." / ",").

§big_mark: String

Thousands separator (",", ".", " ", "'"; "" disables grouping).

§min_grouping_digits: usize

Group thousands only when the integer part has at least 3 + min_grouping_digits digits (CLDR’s minimum grouping digits). 1 (every preset) groups 1000 as 1.000; 2 leaves 2020 alone and groups from 10.000.

§currency_symbol: String

The locale’s currency symbol ("$", "€", "£").

§currency_position: CurrencyPosition

Where the currency symbol goes.

§currency_spacing: String

Text between amount and currency symbol ("" or " ").

§percent_suffix: String

Suffix of percentages ("%" in English, " %" in German / French).

§months_short: [String; 12]

Abbreviated month names, January first (%b).

§months_long: [String; 12]

Full month names, January first (%B).

§days_short: [String; 7]

Abbreviated weekday names, Sunday first (%a).

§days_long: [String; 7]

Full weekday names, Sunday first (%A).

§date_format: String

strftime format of a calendar date (default date-axis labels at day resolution), e.g. "%-d. %b %Y" → 15. Okt. 2026.

§month_format: String

strftime format of a month (default monthly date-axis labels), e.g. "%b %Y" → Okt. 2026.

§time_format: String

strftime format of a time of day, appended to the date for datetimes that are not at midnight, e.g. "%H:%M".

Implementations§

Source§

impl Locale

Source

pub fn en_us() -> Self

English (United States): 1,234.5, $1,234.50, 50%, Oct 15, 2026.

Source

pub fn en_gb() -> Self

English (United Kingdom): 1,234.5, £1,234.50, 50%, 15 Oct 2026.

Source

pub fn de_de() -> Self

German (Germany): 1.234,5, 1.234,50 €, 50 %, 15. Okt. 2026.

Source

pub fn fr_fr() -> Self

French (France): 1 234,5, 1 234,50 €, 50 %, 15 oct. 2026. The thousands mark is a plain space (CLDR uses a narrow no-break space, which many fonts lack); set big_mark to override.

Source

pub fn try_from_tag(tag: &str) -> Option<Self>

The preset for a BCP-47-ish tag, if one matches: case-insensitive, - or _ separated, POSIX suffixes (.UTF-8, @euro) ignored. de* → de_de, fr* → fr_fr, en-GB / en-UK → en_gb, other en* and C / POSIX → en_us.

Source

pub fn from_tag(tag: &str) -> Self

Like try_from_tag, falling back to en_us for unknown tags.

use ggplot_rs::locale::Locale;
assert_eq!(Locale::from_tag("de-DE").tag, "de-DE");
assert_eq!(Locale::from_tag("fr_FR.UTF-8").tag, "fr-FR");
assert_eq!(Locale::from_tag("en-GB").tag, "en-GB");
assert_eq!(Locale::from_tag("xx-YY").tag, "en-US");
Source

pub fn with_decimal_mark(self, mark: &str) -> Self

Replace the decimal mark.

Source

pub fn with_big_mark(self, mark: &str) -> Self

Replace the thousands mark ("" disables grouping).

Source

pub fn with_min_grouping_digits(self, digits: usize) -> Self

Replace the minimum grouping digits (see min_grouping_digits).

Source

pub fn with_currency(self, symbol: &str) -> Self

Use another currency symbol, placed by this locale’s convention: Locale::de_de().with_currency("CHF") formats 1.234,50 CHF.

Source

pub fn currency_affixes(&self, symbol: &str) -> (String, String)

(prefix, suffix) that place symbol by this locale’s convention: ("$", "") for en-US, ("", " €") for de-DE.

Source

pub fn localize_number(&self, s: &str) -> String

Re-render a number formatted the default way (. decimal mark, , or no thousands grouping, optional leading -) with this locale’s marks: "-1234.5" / "-1,234.5" → "-1.234,5" in de-DE. Anything that is not such a number (NaN, inf, text) is returned unchanged.

Source

pub fn parse_number(&self, s: &str) -> Option<f64>

Inverse of localize_number for parsing a label back to a number: strips thousands marks and restores ..

Source

pub fn format_number(&self, v: f64) -> String

Format a break value like the default axis labels (integers verbatim, otherwise up to two decimals, trailing zeros trimmed) with this locale’s marks: 1234.5 → "1.234,5" in de-DE.

Source

pub fn strftime(&self, epoch_secs: i64, fmt: &str) -> String

Format epoch seconds (UTC) with a strftime-style format, using this locale’s month and weekday names. Supported: %Y %y %m %-m %b %B %d %-d %e %a %A %H %M %S %%.

Source

pub fn format_datetime(&self, epoch_secs: i64) -> String

Format epoch seconds (UTC) as this locale’s date (date_format), plus time_format when not at midnight.

Trait Implementations§

Source§

impl Clone for Locale

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Locale

Source§

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

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

impl Default for Locale

Source§

impl FromStr for Locale

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Locale::from_tag (never fails; unknown tags give en-US).

Source§

type Err = !

The associated error which can be returned from parsing.
Source§

impl PartialEq for Locale

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Locale

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V