Debian Codegraph @

debian/rust-vendor/icu_decimal/src/parts.rs

raw
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 //! Parts of a formatted decimal.
6 //!
7 //! # Examples
8 //!
9 //! ```
10 //! use icu::decimal::parts;
11 //! use icu::decimal::DecimalFormatter;
12 //! use icu::locale::locale;
13 //! use writeable::assert_writeable_parts_eq;
14 //!
15 //! let formatter = DecimalFormatter::try_new(
16 //! locale!("en").into(),
17 //! Default::default(),
18 //! )
19 //! .unwrap();
20 //!
21 //! let decimal = "-987654.321".parse().unwrap();
22 //!
23 //! // Missing data is filled in on a best-effort basis, and an error is signaled.
24 //! assert_writeable_parts_eq!(
25 //! formatter.format(&decimal),
26 //! "-987,654.321",
27 //! [
28 //! (0, 1, parts::MINUS_SIGN),
29 //! (1, 8, parts::INTEGER),
30 //! (4, 5, parts::GROUP),
31 //! (8, 9, parts::DECIMAL),
32 //! (9, 12, parts::FRACTION),
33 //! ]
34 //! );
35 //! ```
36
37 use writeable::Part;
38
39 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
40 pub const PLUS_SIGN: Part = Part {
41 category: "decimal",
42 value: "plusSign",
43 };
44
45 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
46 pub const MINUS_SIGN: Part = Part {
47 category: "decimal",
48 value: "minusSign",
49 };
50
51 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
52 pub const INTEGER: Part = Part {
53 category: "decimal",
54 value: "integer",
55 };
56
57 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
58 pub const FRACTION: Part = Part {
59 category: "decimal",
60 value: "fraction",
61 };
62
63 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
64 pub const GROUP: Part = Part {
65 category: "decimal",
66 value: "group",
67 };
68
69 /// A [`Part`] used by [`FormattedDecimal`](super::FormattedDecimal).
70 pub const DECIMAL: Part = Part {
71 category: "decimal",
72 value: "decimal",
73 };