Expand description
mf2-runtime — the MessageFormat 2 evaluator of mf2-two: it formats a message from a catalog, walking
mf2-catalog’s views in place — resolution, declarations (lazily, each at
most once), selection, fallback, the Default Bidi Strategy, format to
parts, markup, the u: options — and it holds the function registry, the
custom-function API and the core functions: :string, and :number,
:integer, :offset with their complete semantics and neutral symbols.
| Item | What |
|---|---|
Formatter | the entry point: simple, write, parts, *_named |
Sink, PartSink, ErrorSink | where output and errors go |
Arg, Value, Number | arguments and resolved values |
Function, Registry, functions | handlers; a registry names only the handlers its corpus uses, and no other is linked |
Host | NFC, float text, zone offsets, a date formatter, a number formatter (intl) from the platform |
DateTime, TimeZone, NumberSpec, Digits, Measure | what the function crates and custom functions build on |
Client-path code: no_std + alloc, forbid(unsafe_code), no
core::fmt, no panicking operation; built-in handlers never allocate.
§The user guide
Getting started, call sites, delivery modes, switching language,
accessibility, migrating from leptos-fluent, and what 1.x promises
(versioning.md): the user guide is the docs/ directory of the
mf2-two repository. An application reaches this crate through
mf2, which re-exports it; a custom function is
written against Function.
Modules§
- functions
- The core functions (
plans/03-runtime.md§3, §5.1): statics for acrate::Registry. An application’s generated registry names only the ones its corpus uses (closed world, B13).
Structs§
- Catalog
- A validated
.mf2bcatalog (F2): the fetched buffer and the offsetsnewfound. Share it asRc<Catalog>/Arc<Catalog>. - Date
- A civil date in the proleptic Gregorian calendar (ISO 8601).
- Date
Style - The date part:
dateFields/fieldsanddateLength/length. - Date
Time - A date/time value: an application’s argument (
crate::Arg::DateTime,crate::CustomValue::as_date_time), a literal a date/time function parsed, or what:datetime,:dateor:timeresolved — the value with itsDateTimeOptions. Build it with the constructors. - Date
Time Options - What
:datetime,:dateor:timeresolved (datetime.md). The override options (time_zone,hour12,calendar) travel with the value into a later date/time expression that takes it as its operand. - Date
Time Request - What a host’s date formatter receives (
Host::format_date_time,datetime-intl): an instant and how to show it. - Digit
Options - ECMA-402’s digit options as
SetNumberFormatDigitOptionsresolved them for MF2 — so never a setIntlrejects: where it would throw, the numeric function reported Bad Option and dropped or replaced the option (plans/03-runtime.md§5.3). - Digits
- Digits to show (
plans/03-runtime.md§2.7): a resolved number’s rounded display digits (Number::digits), or a number’s exact value (Number::exact_digits) — whatmf2-fn-numberlocalizes. - Expression
Part - A formatted placeholder: its resolved value and how it formats.
- FnContext
- What a handler may see of the formatting context: read-only and minimal (formatting.md, “Function Handler”).
- Format
Context - What formatting needs beyond the catalog and the registry; build it
with
FormatContext::new. - Formatter
- Formats messages of one catalog.
- Markup
Options - The options of a
MarkupPart:(name, value)in source order. - Markup
Part - A markup placeholder.
- Measure
- A number with a currency or a unit, and the options its function added.
- MsgId
- A message id: which message of a build’s catalogs.
tr!and the generated module make them; an application compares, hashes and passes them, and never builds one from a number. - NoErrors
- Discards errors: the release client’s policy (
plans/03-runtime.md§8). - Number
- An exact decimal and, once a numeric handler resolved it, its resolved options and its display form. Opaque: the digit backend is internal (owner decision 1).
- Number
Request - A number for a
NumberFormatter(the host’s,Host::numbers). Built by the runtime; a host reads it. - Number
Spec - How one numeric function resolves (
plans/03-runtime.md§2.7): which options it reads, its fraction-digit defaults, whether it rounds to an integer, whether it selects, and the power of ten it applies. Closed world: a handler is a spec. - Operands
- The UTS #35 operands of a non-negative decimal (Part 3 §5.1.1): the
formatter’s side of the contract of
plans/02-catalog-format.md§4.1.nis integral ifft == 0, and then equalsi. - Option
Value - A resolved option value.
- Options
- The resolved options passed to
Function::resolve. Their order is not significant; a repeated name (a Duplicate Option Name, which the build rejects) resolves to the last. - Registry
- The function handlers an application links: closed world (B13). Build
code generates it from exactly the functions the corpus uses, e.g.
static REGISTRY: Registry = Registry::new(&[("integer", &mf2_runtime::functions::INTEGER)]);— an unused handler is never referenced, so never linked. - Time
- A wall-clock time, to the millisecond (a date/time literal has at most three fraction digits).
- Time
Zone - The formatting context’s time zone: the default of
timeZone(plans/03-runtime.md§6). Owned — a per-request zone need not be'static.
Enums§
- Arg
- A positional argument: slot
iof the call site isargs[i](the manifest’s slot order). Small on purpose: every variant is a code path in the wasm. Non-exhaustive, so variants can be added. - Bidi
Strategy - A bidirectional isolation strategy (formatting.md, “Handling Bidirectional Text”).
- Category
- A CLDR plural category.
- Currency
Display :currency’scurrencyDisplay.- Date
Fields dateFields/fields.- Date
Length dateLength/length.- Dir
- Text direction.
- Fallback
Source - What a fallback value shows (formatting.md, “Fallback Resolution”).
- Format
Error - An error reported while formatting. Formatting still produces output.
- Grouping
useGrouping. Core output never groups;mf2-fn-numberhonours it.- Isolation
- A bidi isolation control.
- Markup
Kind - The three forms of markup.
- Measure
Unit - What a
Measuremeasures. - Number
Out - Where
NumberFormatter::formatwrites: text, or sub-parts (formatToParts:integer,group,decimal,fraction,minusSign,plusSign,percentSign,currency,unit,literal, …). - Number
Style - How a
NumberRequestis shown. - Part
- A part of a formatted message. Concatenated, the parts are the string output.
- Rounding
Mode roundingMode(ECMA-402’s names and meanings).- Rounding
Priority roundingPriority.- Sign
- The sign a formatted number shows, after
signDisplay. - Sign
Display signDisplay.- Time
Precision timePrecision/precision.- Unit
Display :unit’sunitDisplay.- Value
- A resolved value’s data. The handler that resolved it decides how it
formats and selects; a value no handler resolved (a literal, an
argument) is unannotated (
plans/03-runtime.md§2.6). - Zone
Option - A time zone as an option value (
timeZone) or a formatting target. - Zone
Style timeZoneStyle.
Traits§
- Custom
Value - An application’s own argument type: what it converts to.
- Error
Sink - An error sink.
- Function
- A function handler.
:string,:number,:integer,:offsetare incrate::functions; custom functions implement the same trait (the suite’s:test:*functions are written against it). - Host
- The platform services the runtime needs.
- Number
Formatter - A number formatter for the
intloption (Host::numbers;plans/03-runtime.md§2.7, §5.3): the final “value + resolved options → text” step and the plural category, where the numeric functions keep MF2’s semantics in Rust.mf2-host-webimplements it withIntl. - Part
Sink - Receives the parts of a formatted message, in order.
- Sink
- A text sink.
- SubPart
Sink - Receives the sub-parts of a formatted expression (a number’s
minusSign,integer,decimal,fraction, …).
Functions§
- is_
zone_ name - Whether
sis a well-formed RFC 9557time-zone-name: parts separated by/, each starting with a letter,.or_, then letters, digits,.,_,-or+, and neither.nor...