1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use std::{
cmp::Ordering,
fmt,
hash::{Hash, Hasher},
};
#[derive(Debug, Eq)]
pub struct CainStr<'a> {
src: &'a str,
}
impl PartialEq for CainStr<'_> {
fn eq(&self, other: &Self) -> bool {
self.src.to_lowercase().eq(&other.src.to_lowercase())
}
}
impl Ord for CainStr<'_> {
fn cmp(&self, other: &Self) -> Ordering {
self.src.to_lowercase().cmp(&other.src.to_lowercase())
}
}
impl PartialOrd for CainStr<'_> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Hash for CainStr<'_> {
fn hash<H>(&self, h: &mut H) where H: Hasher {
self.src.to_lowercase().hash(h);
}
}
impl fmt::Display for CainStr<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(self.src)
}
}
impl<'a> From<&'a str> for CainStr<'a> {
fn from(src: &'a str) -> Self {
Self { src }
}
}
impl<'a> From<CainStr<'a>> for &'a str {
fn from(cain_str: CainStr<'a>) -> &'a str {
cain_str.src
}
}
impl AsRef<str> for CainStr<'_> {
fn as_ref(&self) -> &str {
self.src
}
}