mf2_model/lib.rs
1//! `mf2-model` — the Unicode MessageFormat 2 (MF2) interchange data model as
2//! Rust types, plus the identities and error kinds every Rust MF2 crate shares
3//! and the [`Frontend`] trait a parser implements.
4//!
5//! The data model's structs mirror the specification's `message.json` field
6//! for field, and code builds them by literal; a later MF2 that defines a
7//! new structure adds a variant, which is why the enums are
8//! `#[non_exhaustive]`.
9//!
10//! * [`MsgId`], [`Dir`] — identities shared with the catalog and the runtime.
11//! * [`is_name_start`], [`is_name_char`] — the ABNF's name classes, shared by
12//! the two frontends.
13//! * [`ErrorKind`], [`ErrorClass`], [`Span`], [`Diagnostic`], [`Diagnostics`] —
14//! the 13 error kinds of the WG test suite plus two, and how a frontend
15//! reports them.
16//! * [`Message`] and everything below it — the specification's interchange
17//! data model, one-to-one.
18//! * [`Parsed`], [`Frontend`] — the parser boundary.
19//!
20//! Values are kept **as written**: nothing in this crate normalizes. Names
21//! exclude the bidi marks the syntax allows around them (spec, "Names and
22//! Identifiers"); equality is exact (bytewise), which is what the round-trip
23//! properties of the conformance tests need. Normalization belongs to
24//! comparison (validation in `mf2-syntax`) and to catalog encoding.
25//!
26//! `#![no_std]` + `alloc`, no dependencies by default. Features: `serde` (JSON
27//! that validates against the specification's `message.json`) and `suite-names` (error kinds ↔ the
28//! suite's strings). The client wasm links only [`MsgId`], [`Dir`] and
29//! [`ErrorKind`].
30//!
31//! # The user guide
32//!
33//! The [Rust MF2 book](https://evancarroll.github.io/rust-mf2/) is the user
34//! guide: how the crates fit together, web and native applications, the
35//! command line, and what 2.x promises.
36//! An application formatting messages starts at
37//! [`mf2`](https://docs.rs/mf2); this crate is for tools that work on the
38//! data model itself, with `mf2-syntax`.
39
40#![warn(missing_docs)]
41// docs.rs (`cargo xtask docs-rs`): each feature-gated item says which features it needs.
42#![cfg_attr(docsrs, feature(doc_cfg))]
43#![no_std]
44#![forbid(unsafe_code)]
45
46extern crate alloc;
47
48mod chars;
49mod diagnostic;
50mod expression;
51mod frontend;
52mod id;
53#[cfg(feature = "serde")]
54mod json;
55mod message;
56mod pattern;
57
58#[doc(hidden)]
59pub use alloc::borrow::Cow;
60
61pub use chars::{is_name_char, is_name_start};
62pub use diagnostic::{Diagnostic, Diagnostics, ErrorClass, ErrorKind, Span};
63pub use expression::{
64 Attributes, Expression, FunctionExpression, FunctionRef, Literal, LiteralExpression, Markup,
65 MarkupKind, OptionValue, Options, VariableExpression, VariableRef, split_identifier,
66};
67pub use frontend::{Frontend, Parsed};
68pub use id::{Dir, MsgId};
69pub use message::{
70 CatchAllKey, Declaration, InputDeclaration, Key, LocalDeclaration, Message, PatternMessage,
71 SelectMessage, Variant,
72};
73pub use pattern::{Pattern, PatternPart};