mf2_catalog/lib.rs
1//! `mf2-catalog` — the `.mf2b` binary catalog of Rust MF2: one locale's
2//! messages and locale data, as a lossless encoding of the MF2 data model that the client reads in place.
3//!
4//! An application meets one type of this crate: [`Catalog`], a loaded
5//! catalog, which `mf2::leptos` and `mf2::axum` load and serve for it and
6//! which [`mf2_runtime`'s formatter](https://docs.rs/mf2-runtime) formats
7//! from — with its errors ([`CatalogError`], and on the build side
8//! `WriteError` and `ManifestError`). Everything else here is the byte
9//! format, which 1.x does not promise (`docs/versioning.md`: rebuild the
10//! server and the client together), and is hidden from the documentation:
11//!
12//! | Part | Feature | Side |
13//! |---|---|---|
14//! | `Catalog` and its views (`MsgView`, …) — the reader | *(always)* | client: `no_std`, no allocation, no panics, no `core::fmt` |
15//! | `number`, `currency`, `unit` — views of the `number.*`, `currency.data` and `unit.data` LOCALE entries (`mf2-fn-number` reads them) | *(always)* | client, same rules |
16//! | `Manifest` — `manifest.mf2m` and `manifest_hash` | `manifest` | build |
17//! | `writer` — `writer::catalog`, `writer::single` | `writer` | build |
18//! | `decode()` — the model-rebuilding decoder (for tests) | `decode` | build |
19//! | [`content_hash`] — the hash in a catalog's file name | `content-hash` | build, native |
20//!
21//! The reader is client-path code: `Catalog::new` takes the fetched buffer
22//! and validates its structure once, in linear time; every accessor is a
23//! bounds-checked O(1) read that never panics; strings are checked as UTF-8
24//! when read; nothing formats. `StrRef` is opaque and loading is one
25//! function — the two seams kept for catalog text as JS strings.
26//!
27//! The byte format is version 1; its constants are in `format`.
28//!
29//! # The user guide
30//!
31//! The [Rust MF2 book](https://evancarroll.github.io/rust-mf2/) is the user
32//! guide: how the crates fit together, web and native applications, the
33//! command line, and what 2.x promises.
34//! An application starts at
35//! [`mf2`](https://docs.rs/mf2).
36
37#![warn(missing_docs, missing_debug_implementations)]
38// docs.rs (`cargo xtask docs-rs`): each feature-gated item says which features it needs.
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![no_std]
41#![forbid(unsafe_code)]
42#![deny(
43 clippy::unwrap_used,
44 clippy::expect_used,
45 clippy::indexing_slicing,
46 clippy::panic
47)]
48
49extern crate alloc;
50
51mod bytes;
52#[cfg(feature = "content-hash")]
53mod content_hash;
54#[doc(hidden)]
55pub mod currency;
56#[cfg(feature = "decode")]
57mod decode;
58mod error;
59#[doc(hidden)]
60pub mod format;
61#[cfg(feature = "manifest")]
62mod manifest;
63mod markup;
64#[doc(hidden)]
65pub mod number;
66mod plural;
67mod reader;
68#[doc(hidden)]
69pub mod unit;
70mod view;
71#[cfg(feature = "writer")]
72#[doc(hidden)]
73pub mod writer;
74
75pub use mf2_model::{Dir, MsgId};
76
77#[cfg(feature = "content-hash")]
78pub use content_hash::{CONTENT_HASH_LEN, content_hash};
79#[cfg(feature = "decode")]
80#[doc(hidden)]
81pub use decode::{Decoded, decode, decode_report};
82pub use error::CatalogError;
83#[cfg(feature = "decode")]
84#[doc(hidden)]
85pub use error::DecodeError;
86#[cfg(feature = "manifest")]
87pub use error::ManifestError;
88#[cfg(feature = "writer")]
89pub use error::WriteError;
90#[cfg(feature = "manifest")]
91#[doc(hidden)]
92pub use manifest::Manifest;
93#[doc(hidden)]
94pub use markup::markup_key;
95pub use reader::{Catalog, CldrVersion};
96#[doc(hidden)]
97pub use reader::{Entry, StrRef};
98#[doc(hidden)]
99pub use view::{
100 Body, DeclView, Declarations, ExprView, FunctionView, KeyView, Keys, Malformed, MarkupView,
101 MsgView, Names, Operand, OptionsView, PartView, Parts, PatternView, SelectView, Selectors,
102 VarRef, VariantView, Variants,
103};