Skip to main content

Crate mf2_fn_number

Crate mf2_fn_number 

Source
Expand description

mf2-fn-number — the localized numeric functions of Rust MF2: the runtime’s numeric core (mf2_runtime::NumberSpec, Number::resolve) resolves — operand rules, every digit and rounding option, signDisplay, inheritance, selection — and this crate writes the rounded digits with the catalog’s locale data (its number.symbols and number.patterns entries): decimal and group separators, signs, the numbering system’s digits, grouping (useGrouping auto / always / min2 / never, with the locale’s minimum grouping digits), and the percent pattern.

StaticFunction
NUMBER, INTEGER, OFFSET:number, :integer, :offset, localized (the core’s are neutral)
PERCENT:percent
CURRENCY, UNIT:currency, :unit (Draft): a Measure with the catalog’s currency.data / unit.data
NUMBERSunannotated numbers, localized: Registry::with_numbers(&NUMBERS)

With feature intl on wasm32-unknown-unknown ([mf2_runtime::INTL_NUMBERS]) the text comes from the host’s number formatter (the browser’s Intl.NumberFormat) instead.

Closed world: an application’s registry names only the handlers its corpus uses. Selection, exact-match keys and plural operands are the core’s (neutral digits, the formatted digits’ plural category): a localized handler only changes the text. Client-path code: no_std, forbid(unsafe_code), no core::fmt, no panicking operation, no allocation.

§The user guide

The Rust MF2 book is the user guide: how the crates fit together, web and native applications, the command line, and what 2.x promises. An application reaches this crate through mf2, as mf2::fn_number (feature fn-number).

Structs§

CurrencyFunction
:currency (functions/number.md).
NumberFunction
A localized numeric handler: :number, :integer, :offset or :percent.
Unannotated
Unannotated numbers — integer, float and decimal arguments — as their exact value (no rounding) with the locale’s symbols, grouping (auto) and digits: the handler of Registry::with_numbers (plans/03-runtime.md §2.7). The evaluator checks the value first (a non-finite float is a Bad Operand, as without this handler).
UnitFunction
:unit (functions/number.md, Draft).

Statics§

CURRENCY
:currency.
INTEGER
:integer (functions/number.md), localized.
NUMBER
:number (functions/number.md), localized.
NUMBERS
The handler for unannotated numbers: Registry::new(…).with_numbers(&NUMBERS).
OFFSET
:offset (functions/number.md), localized.
PERCENT
:percent (functions/number.md): the value × 100 with the locale’s percent pattern; selects on the scaled value (plural).
UNIT
:unit.