Macro icu_locale::locale
macro_rules! locale { ($locale:literal) => { ... }; }
Expand description
A macro allowing for compile-time construction of valid Locale
s.
The macro will perform syntax normalization of the tag.
§Examples
use icu::locale::{locale, Locale};
const DE_AT: Locale = locale!("de_at");
let de_at: Locale = "de_at".parse().unwrap();
assert_eq!(DE_AT, de_at);
Note: The macro cannot produce locales with more than one variant or multiple extensions
(only single keyword unicode extension is supported) due to const
limitations (see Heap Allocations in Constants
):
ⓘ
icu::locale::locale!("sl-IT-rozaj-biske-1994");
Use runtime parsing instead:
"sl-IT-rozaj-biske-1994"
.parse::<icu::locale::Locale>()
.unwrap();
Locales with multiple keys are not supported
ⓘ
icu::locale::locale!("th-TH-u-ca-buddhist-nu-thai");
Use runtime parsing instead:
"th-TH-u-ca-buddhist-nu-thai"
.parse::<icu::locale::Locale>()
.unwrap();
Locales with attributes are not supported
ⓘ
icu::locale::locale!("en-US-u-foobar-ca-buddhist");
Use runtime parsing instead:
"en-US-u-foobar-ca-buddhist"
.parse::<icu::locale::Locale>()
.unwrap();
Locales with single key but multiple types are not supported
ⓘ
icu::locale::locale!("en-US-u-ca-islamic-umalqura");
Use runtime parsing instead:
"en-US-u-ca-islamic-umalqura"
.parse::<icu::locale::Locale>()
.unwrap();