Skip to main content

icu_locale_core/
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// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
6#![cfg_attr(not(any(test, doc)), no_std)]
7#![cfg_attr(
8    not(test),
9    deny(
10        clippy::indexing_slicing,
11        clippy::unwrap_used,
12        clippy::expect_used,
13        clippy::panic,
14    )
15)]
16#![warn(missing_docs)]
17
18//! Parsing, manipulating, and serializing Unicode Language and Locale Identifiers.
19//!
20//! This module is published as its own crate ([`icu_locale_core`](https://docs.rs/icu_locale_core/latest/icu_locale_core/))
21//! and as part of the [`icu`](https://docs.rs/icu/latest/icu/) crate. See the latter for more details on the ICU4X project.
22//!
23//! The module provides algorithms for parsing a string into a well-formed language or locale identifier
24//! as defined by [`UTS #35: Unicode LDML 3. Unicode Language and Locale Identifiers`]. Additionally
25//! the module provides [`preferences`] interface for operations on locale preferences and conversions
26//! from and to locale unicode extensions.
27//!
28//! [`Locale`] is the most common structure to use for storing information about a language,
29//! script, region, variants and extensions. In almost all cases, this struct should be used as the
30//! base unit for all locale management operations.
31//!
32//! [`LanguageIdentifier`] is a strict subset of [`Locale`] which can be useful in a narrow range of
33//! cases where [`Unicode Extensions`] are not relevant.
34//!
35//! If in doubt, use [`Locale`].
36//!
37//! # Examples
38//!
39//! ```
40//! use icu::locale::Locale;
41//! use icu::locale::{
42//!     locale,
43//!     subtags::{language, region},
44//! };
45//!
46//! let mut loc: Locale = locale!("en-US");
47//!
48//! assert_eq!(loc.id.language, language!("en"));
49//! assert_eq!(loc.id.script, None);
50//! assert_eq!(loc.id.region, Some(region!("US")));
51//! assert_eq!(loc.id.variants.len(), 0);
52//!
53//! loc.id.region = Some(region!("GB"));
54//!
55//! assert_eq!(loc, locale!("en-GB"));
56//! ```
57//!
58//! For more details, see [`Locale`] and [`LanguageIdentifier`].
59//!
60//! [`UTS #35: Unicode LDML 3. Unicode Language and Locale Identifiers`]: https://unicode.org/reports/tr35/tr35.html#Unicode_Language_and_Locale_Identifiers
61//! [`ICU4X`]: ../icu/index.html
62//! [`Unicode Extensions`]: extensions
63
64#[cfg(feature = "alloc")]
65extern crate alloc;
66
67#[macro_use]
68mod helpers;
69
70mod data;
71mod langid;
72mod locale;
73mod macros;
74mod parser;
75mod shortvec;
76
77pub use data::DataLocale;
78pub use langid::LanguageIdentifier;
79pub use locale::Locale;
80pub use parser::ParseError;
81
82pub mod extensions;
83#[macro_use]
84pub mod subtags;
85pub mod preferences;
86pub mod zerovec;
87
88#[cfg(all(feature = "alloc", feature = "serde"))]
89mod serde;
90
91#[cfg(feature = "databake")]
92mod databake;