icu_list/
options.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//! Options used by types in this crate
6
7/// A list of options set by the developer to adjust the behavior of the ListFormatter.
8///
9/// # Examples
10/// ```
11/// use icu::list::options::{ListFormatterOptions, ListLength};
12///
13/// let options = ListFormatterOptions::default().with_length(ListLength::Wide);
14/// ```
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16#[non_exhaustive]
17pub struct ListFormatterOptions {
18    /// The length variant should reflect available space for the list.
19    pub length: Option<ListLength>,
20}
21
22impl Default for ListFormatterOptions {
23    fn default() -> Self {
24        Self::default()
25    }
26}
27
28impl ListFormatterOptions {
29    /// Constructs a new [`ListFormatterOptions`] struct.
30    pub const fn default() -> Self {
31        Self { length: None }
32    }
33
34    /// Auguments the struct with the set [`ListLength`].
35    pub const fn with_length(mut self, length: ListLength) -> Self {
36        self.length = Some(length);
37        self
38    }
39}
40
41/// Represents the style of a list. See the
42/// [CLDR spec](https://unicode.org/reports/tr35/tr35-general.html#ListPatterns)
43/// for an explanation of the different styles.
44#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Default)]
45#[non_exhaustive]
46pub enum ListLength {
47    /// A typical list
48    #[default]
49    Wide,
50    /// A shorter list
51    Short,
52    /// The shortest type of list
53    Narrow,
54    // *Important*: When adding a variant here, make sure the code in
55    // ListFormatterPatterns::{start, middle, end, pair} stays panic-free!
56}