icu_provider_fs/
lib.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5//! `icu_provider_fs` is one of the [`ICU4X`] components.
6//!
7//! It reads ICU4X data files from the filesystem in a given directory.
8//!
9//! # Examples
10//!
11//! ```
12//! use icu_provider_fs::FsDataProvider;
13//!
14//! let provider = FsDataProvider::try_new("/path/to/data/directory".into())
15//!     .expect_err("Specify a real directory in the line above");
16//! ```
17//!
18//! # Directory Structure
19//!
20//! The ICU4X data directory has a file named `manifest.json` at the root, and a nested structure
21//! with a data marker ([`DataMarkerInfo`](icu_provider::DataMarkerInfo)), and locale ([`DataLocale`](icu_provider::DataLocale))
22//! as the leaf data files. For example, Arabic JSON data for cardinal plural rules lives at `plurals/cardinal@1/ar.json`.
23//!
24//! The exact form of the directory structure may change over time. ICU4X uses metadata from
25//! `manifest.json` to dynamically interpret different versions of the directory structure.
26//!
27//! ```text
28//! ├── manifest.json
29//! ├── dates
30//! │   └── gregory@1
31//! │       ├── ar-EG.json
32//! │       ├── ar.json
33//! │       ├── be.json
34//! │       ⋮
35//! │       └── und.json
36//! └── plurals
37//!     ├── cardinal@1
38//!     │   ├── ar.json
39//!     │   ├── be.json
40//!     │   ⋮
41//!     │   └── und.json
42//!     └── ordinal@1
43//!         ├── ar.json
44//!         ├── be.json
45//!         ⋮
46//!         └── und.json
47//! ```
48//!
49//! # Resource Formats
50//!
51//! `ICU4X` data can be stored in different formats. At the moment there are:
52//!
53//! * JSON - Textual format, easy to read
54//! * Postcard - Binary, small `#[no_std]` resource format
55//! * Bincode - Binary, fast resource format
56//!
57//! The directory passed to the [`FsDataProvider`] constructor may contain either of them.
58//!
59//! *Notice:* In order for ICU4X to be able to *deserialize* the returned data, the corresponding
60//! Cargo feature has to be activated on the [`icu_provider`] crate. See
61//! [`AsDeserializingBufferProvider::as_deserializing`](icu_provider::buf::AsDeserializingBufferProvider).
62//!
63//! # Exporting data
64//!
65//! To generate the data required for [`FsDataProvider`], run the following:
66//!
67//! ```bash
68//! icu4x-datagen --markers all --locales full --format fs
69//! ```
70//!
71//! To export `postcard` format, use
72//!
73//! ```bash
74//! icu4x-datagen --markers all --locales full --format fs --syntax postcard
75//! ```
76//!
77//! [`ICU4X`]: ../icu/index.html
78
79// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
80#![cfg_attr(
81    not(test),
82    deny(
83        clippy::indexing_slicing,
84        clippy::unwrap_used,
85        clippy::expect_used,
86        clippy::panic,
87        clippy::exhaustive_structs,
88        clippy::exhaustive_enums,
89        clippy::trivially_copy_pass_by_ref,
90        missing_debug_implementations,
91    )
92)]
93#![warn(missing_docs)]
94
95mod datapath;
96mod fs_data_provider;
97mod manifest;
98
99#[cfg(feature = "export")]
100pub mod export;
101
102pub use fs_data_provider::FsDataProvider;