langtag/normal/
region.rs

1use std::hash::Hash;
2
3use static_regular_grammar::RegularGrammar;
4
5use crate::utils::{self, str_eq};
6
7/// Region subtag.
8///
9/// Region subtags are used to indicate linguistic variations associated
10/// with or appropriate to a specific country, territory, or region.
11/// Typically, a region subtag is used to indicate variations such as
12/// regional dialects or usage, or region-specific spelling conventions.
13/// It can also be used to indicate that content is expressed in a way
14/// that is appropriate for use throughout a region, for instance,
15/// Spanish content tailored to be useful throughout Latin America.
16#[derive(RegularGrammar)]
17#[grammar(file = "src/grammar.abnf", entry_point = "region")]
18#[grammar(sized(
19	RegionBuf,
20	derive(Debug, Display, PartialEq, Eq, PartialOrd, Ord, Hash)
21))]
22#[cfg_attr(feature = "serde", grammar(serde))]
23pub struct Region(str);
24
25impl PartialEq for Region {
26	fn eq(&self, other: &Self) -> bool {
27		utils::case_insensitive_eq(self.as_bytes(), other.as_bytes())
28	}
29}
30
31impl Eq for Region {}
32
33str_eq!(Region);
34str_eq!(RegionBuf);
35
36impl PartialOrd for Region {
37	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
38		Some(self.cmp(other))
39	}
40}
41
42impl Ord for Region {
43	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
44		utils::case_insensitive_cmp(self.as_bytes(), other.as_bytes())
45	}
46}
47
48impl Hash for Region {
49	fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
50		utils::case_insensitive_hash(self.as_bytes(), state)
51	}
52}