Skip to main content

Crate mf2_resource

Crate mf2_resource 

Source
Expand description

mf2-resource — the W3C Message Resource container for MessageFormat 2: a parser, a serializer and the data model, generic over the message type.

Unicode defines no file format for MF2; its specification leaves that to a future message resource specification. Rust MF2 adopts the draft being written for it, incubated by the W3C i18n WG.

# A comment about the file.
@locale en-US
---

chat-send = Send

@param $count - How many people are in the room; a whole number.
users-online =
  .input {$count :integer}
  .match $count
  one {{{$count} user online}}
  *   {{{$count} users online}}

[hotkeys]
# → id "hotkeys.release"
release = Release {#kbd}?{/kbd} to close

§Not part of 1.x’s promise

mf2-build and the mf2 command line read and write .mf2 files with this crate; an application never names it. What 2.x promises is the file format as mf2 fmt writes it (docs/versioning.md), not this Rust API: it mirrors a draft, and follows the draft as it changes. Its items are therefore hidden from the documentation.

Entry pointGives
parsea Resource of MF2 sources as written, plus the syntax errors found
Resource::map_valuesthe draft’s Resource<Message>: the same tree with parsed messages
serialize / serialize_withcanonical source (mf2 fmt)
LineIndexa byte offset as a line and a column
ValueMapa cooked value’s offset back to where the file wrote it

§The draft is not vendored

The draft states no license, so nothing is copied from it: this crate implements a grammar written from the draft at a pinned revision. Where the draft and this crate disagree, the draft wins, and the crate follows it. The same holds for the JSON shape behind the serde feature.

#![no_std] + alloc; never linked into the client wasm.

§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. Its getting-started chapter shows the files this crate reads, and its versioning chapter what 2.x promises about their format.