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
use unicase::UniCase;
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub enum CaseSensitivity {
Insensitive(UniCase<String>),
Sensitive(String),
}
impl AsRef<str> for CaseSensitivity {
fn as_ref(&self) -> &str {
match self {
Self::Insensitive(u) => u.as_str(),
Self::Sensitive(s) => s.as_str(),
}
}
}
impl PartialEq<str> for CaseSensitivity {
fn eq(&self, other: &str) -> bool {
match self {
Self::Insensitive(u) => u == &UniCase::new(other),
Self::Sensitive(s) => s == other,
}
}
}
#[cfg(test)]
mod tests {
use super::CaseSensitivity;
use static_assertions::assert_impl_all;
use std::{fmt::Debug, hash::Hash};
assert_impl_all!(
CaseSensitivity: AsRef<str>,
Clone,
Debug,
Eq,
Hash,
PartialEq,
PartialEq<str>,
Send,
Sync
);
}