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
96
97
98
99
100
101
102
103
use std::{
cmp::Ordering,
fmt,
hash::{Hash, Hasher},
};
#[derive(Debug, Eq)]
pub struct CainString {
src: String,
}
impl PartialEq for CainString {
fn eq(&self, other: &Self) -> bool {
self.src.to_lowercase().eq(&other.src.to_lowercase())
}
}
impl Ord for CainString {
fn cmp(&self, other: &Self) -> Ordering {
self.src.to_lowercase().cmp(&other.src.to_lowercase())
}
}
impl PartialOrd for CainString {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Hash for CainString {
fn hash<H>(&self, h: &mut H) where H: Hasher {
self.src.to_lowercase().hash(h);
}
}
impl fmt::Display for CainString {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
f.write_str(&self.src)
}
}
impl From<String> for CainString {
fn from(src: String) -> Self {
Self { src }
}
}
impl From<CainString> for String {
fn from(cain_str: CainString) -> String {
cain_str.src
}
}
impl AsRef<str> for CainString {
fn as_ref(&self) -> &str {
&self.src
}
}
impl AsMut<String> for CainString {
fn as_mut(&mut self) -> &mut String {
&mut self.src
}
}