1use core::hash::Hash;
2
3use crate::utils;
4
5#[derive(static_automata::Validate, str_newtype::StrNewType)]
15#[automaton(crate::grammar::Region)]
16#[newtype(
17 no_deref,
18 ord([u8], &[u8], str, &str)
19)]
20#[cfg_attr(
21 feature = "std",
22 newtype(ord(Vec<u8>, String), owned(RegionBuf, derive(PartialEq, Eq, PartialOrd, Ord, Hash)))
23)]
24#[cfg_attr(feature = "serde", newtype(serde))]
25pub struct Region(str);
26
27impl PartialEq for Region {
28 fn eq(&self, other: &Self) -> bool {
29 utils::case_insensitive_eq(self.as_bytes(), other.as_bytes())
30 }
31}
32
33impl Eq for Region {}
34
35impl PartialOrd for Region {
36 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
37 Some(self.cmp(other))
38 }
39}
40
41impl Ord for Region {
42 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
43 utils::case_insensitive_cmp(self.as_bytes(), other.as_bytes())
44 }
45}
46
47impl Hash for Region {
48 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
49 utils::case_insensitive_hash(self.as_bytes(), state)
50 }
51}