1use std::hash::Hash;
2
3use static_regular_grammar::RegularGrammar;
4
5use crate::utils::{self, str_eq};
6
7#[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}