icu_list/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//! Formatting lists in a locale-sensitive way.
6//!
7//! This module is published as its own crate ([`icu_list`](https://docs.rs/icu_list/latest/icu_list/))
8//! and as part of the [`icu`](https://docs.rs/icu/latest/icu/) crate. See the latter for more details on the ICU4X project.
9//!
10//! # Examples
11//!
12//! ## Formatting *and* lists in Spanish
13//!
14//! ```
15//! # use icu::list::ListFormatter;
16//! # use icu::list::options::{ListFormatterOptions, ListLength};
17//! # use icu::locale::locale;
18//! # use writeable::*;
19//! #
20//! let list_formatter = ListFormatter::try_new_and(
21//! locale!("es").into(),
22//! ListFormatterOptions::default().with_length(ListLength::Wide),
23//! )
24//! .expect("locale should be present");
25//!
26//! assert_writeable_eq!(
27//! list_formatter.format(["España", "Suiza"].iter()),
28//! "España y Suiza",
29//! );
30//!
31//! // The Spanish 'y' sometimes becomes an 'e':
32//! assert_writeable_eq!(
33//! list_formatter.format(["España", "Suiza", "Italia"].iter()),
34//! "España, Suiza e Italia",
35//! );
36//! ```
37//!
38//! ## Formatting *or* lists in Thai
39//!
40//! ```
41//! # use icu::list::ListFormatter;
42//! # use icu::list::options::{ListFormatterOptions, ListLength};
43//! # use icu::locale::locale;
44//! # use writeable::*;
45//! #
46//! let list_formatter = ListFormatter::try_new_or(
47//! locale!("th").into(),
48//! ListFormatterOptions::default().with_length(ListLength::Short),
49//! )
50//! .expect("locale should be present");
51//!
52//! // We can use any Writeables as inputs
53//! assert_writeable_eq!(list_formatter.format(1..=3), "1, 2 หรือ 3",);
54//! ```
55//!
56//! ## Formatting unit lists in English
57//!
58//! ```
59//! # use icu::list::ListFormatter;
60//! # use icu::list::options::{ListFormatterOptions, ListLength};
61//! # use icu::locale::locale;
62//! # use writeable::*;
63//! #
64//! let list_formatter = ListFormatter::try_new_unit(
65//! locale!("en").into(),
66//! ListFormatterOptions::default().with_length(ListLength::Wide),
67//! )
68//! .expect("locale should be present");
69//!
70//! assert_writeable_eq!(
71//! list_formatter.format(["1ft", "2in"].iter()),
72//! "1ft, 2in",
73//! );
74//! ```
75//! Note: this last example is not fully internationalized. See [icu4x/2192](https://github.com/unicode-org/icu4x/issues/2192)
76//! for full unit handling.
77
78#![cfg_attr(not(any(test, doc)), no_std)]
79#![cfg_attr(
80 not(test),
81 deny(
82 clippy::indexing_slicing,
83 clippy::unwrap_used,
84 clippy::expect_used,
85 clippy::panic,
86 clippy::exhaustive_structs,
87 clippy::exhaustive_enums,
88 clippy::trivially_copy_pass_by_ref,
89 missing_debug_implementations,
90 )
91)]
92#![warn(missing_docs)]
93
94#[cfg(feature = "alloc")]
95extern crate alloc;
96
97mod lazy_automaton;
98mod list_formatter;
99pub mod options;
100mod patterns;
101
102pub mod provider;
103
104pub use list_formatter::*;