pub struct Locale(/* private fields */);Expand description
A locale, packed into a 32-bit identifier.
The identifier is computed from the locale tag by a const fn, so tags
cost nothing at runtime when converted in const context. The tag is
normalized first (surrounding ASCII whitespace trimmed, ASCII lowercase,
_ as -), so fr_CA, FR-ca and fr-CA are the same locale.
The top 15 bits hold the language when it is 1 to 3 ASCII letters (5 bits
per letter, a is 1); the low 17 bits hold a hash of the rest of the tag
(region, script, variants), or 0 when there is none. Tags that do not
start with a 1 to 3 letter language (pseudo) use the language value
0x7FFF and hash the whole tag. Locale::NONE (identifier 0) is the
empty tag.
use embedded_i18n::Locale;
assert_eq!(Locale::new("fr_CA"), Locale::new("FR-ca"));
assert_eq!(Locale::new("en").id(), 0x015C_0000);
assert_eq!(Locale::NONE.id(), 0);Implementations§
Trait Implementations§
impl Copy for Locale
impl Eq for Locale
impl StructuralPartialEq for Locale
Auto Trait Implementations§
impl Forget for Locale
impl Freeze for Locale
impl Move for Locale
impl RefUnwindSafe for Locale
impl Send for Locale
impl Sync for Locale
impl Unpin for Locale
impl UnsafeUnpin for Locale
impl UnwindSafe for Locale
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more