]> git.proxmox.com Git - rustc.git/blame - vendor/icu_list/src/lib.rs
New upstream version 1.71.1+dfsg1
[rustc.git] / vendor / icu_list / src / lib.rs
CommitLineData
487cf647
FG
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, ListLength};
16//! # use icu::locid::locale;
17//! # use writeable::*;
18//! #
19//! let list_formatter = ListFormatter::try_new_and_with_length_unstable(
20//! &icu_testdata::unstable(),
21//! &locale!("es").into(),
22//! ListLength::Wide,
23//! )
24//! .expect("Data should load successfully");
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, ListLength};
42//! # use icu::locid::locale;
43//! # use writeable::*;
44//! #
45//! let list_formatter = ListFormatter::try_new_or_with_length_unstable(
46//! &icu_testdata::unstable(),
47//! &locale!("th").into(),
48//! ListLength::Short,
49//! )
50//! .expect("Data should load successfully");
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, ListLength};
60//! # use icu::locid::locale;
61//! # use writeable::*;
62//! #
63//! let list_formatter = ListFormatter::try_new_unit_with_length_unstable(
64//! &icu_testdata::unstable(),
65//! &locale!("en").into(),
66//! ListLength::Wide,
67//! )
68//! .expect("Data should load successfully");
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(feature = "std"), 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,
49aad941 88 missing_debug_implementations,
487cf647
FG
89 )
90)]
91#![warn(missing_docs)]
92
93extern crate alloc;
94
95mod error;
9ffffee4 96mod lazy_automaton;
487cf647 97mod list_formatter;
9ffffee4 98mod patterns;
487cf647
FG
99
100pub mod provider;
101
102pub use list_formatter::*;
103
104pub use error::ListError;
105
49aad941 106#[doc(no_inline)]
487cf647
FG
107pub use ListError as Error;
108
109/// Represents the style of a list. See the
110/// [CLDR spec](https://unicode.org/reports/tr35/tr35-general.html#ListPatterns)
111/// for an explanation of the different styles.
112#[derive(Copy, Clone, PartialEq, Debug)]
113#[non_exhaustive]
114pub enum ListLength {
115 /// A typical list
116 Wide,
117 /// A shorter list
118 Short,
119 /// The shortest type of list
120 Narrow,
121 // *Important*: When adding a variant here, make sure the code in
122 // ListFormatterPatterns::{start, middle, end, pair} stays panic-free!
123}