Skip to main content

Formatter

Trait Formatter 

Source
pub trait Formatter: Send + Sync {
    // Required methods
    fn locale(&self) -> String;
    fn number(&self, value: f64, options: NumberOptions) -> String;
    fn currency(&self, value: f64, code: &str, options: NumberOptions) -> String;
    fn percent(&self, value: f64, decimals: Option<u32>) -> String;
    fn date(&self, value: DateValue, options: &DateOptions) -> String;
    fn relative_time(&self, value: i64, unit: RelativeUnit) -> String;
    fn plural(&self, value: f64) -> PluralCategory;

    // Provided methods
    fn bytes(&self, value: f64, unit: ByteUnit) -> String { ... }
    fn offset_minutes(&self, _utc_ms: f64) -> i32 { ... }
}
Expand description

What a host supplies per surface (in SurfaceSettings.locale and its own time zone). The core parses date values and picks the relative unit; the formatter localizes. EnglishFormatter is the default.

Required Methods§

Source

fn locale(&self) -> String

BCP 47.

Source

fn number(&self, value: f64, options: NumberOptions) -> String

Source

fn currency(&self, value: f64, code: &str, options: NumberOptions) -> String

code = an upper-case ISO 4217 code.

Source

fn percent(&self, value: f64, decimals: Option<u32>) -> String

value is a ratio: 0.256 → 26%.

Source

fn date(&self, value: DateValue, options: &DateOptions) -> String

Source

fn relative_time(&self, value: i64, unit: RelativeUnit) -> String

value units relative to now (negative = past), truncated by the core.

Source

fn plural(&self, value: f64) -> PluralCategory

Provided Methods§

Source

fn bytes(&self, value: f64, unit: ByteUnit) -> String

A byte size (value already in unit, ≤ 1 fraction digit), like Intl.NumberFormat(locale, {style: "unit", unitDisplay: "short"}). The default: the number through Self::number + the English short unit (byte, kB, MB, GB).

Source

fn offset_minutes(&self, _utc_ms: f64) -> i32

VAPP-191: the surface (team) zone’s UTC offset in minutes at an instant, for the expression date maths (crate::cel). Default UTC.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§