1use std::cmp::Ordering;
2
3use nu_utils::IgnoreCaseExt;
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Copy, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
7pub enum Casing {
8 #[default]
9 Sensitive,
10 Insensitive,
11}
12
13pub(crate) mod private {
14 pub trait Seal {}
15}
16
17pub trait CaseSensitivity: private::Seal + 'static {
18 fn eq(lhs: &str, rhs: &str) -> bool;
19
20 fn cmp(lhs: &str, rhs: &str) -> Ordering;
21}
22
23pub struct CaseSensitive;
24pub struct CaseInsensitive;
25
26impl private::Seal for CaseSensitive {}
27impl private::Seal for CaseInsensitive {}
28
29impl CaseSensitivity for CaseSensitive {
30 #[inline]
31 fn eq(lhs: &str, rhs: &str) -> bool {
32 lhs == rhs
33 }
34
35 #[inline]
36 fn cmp(lhs: &str, rhs: &str) -> Ordering {
37 lhs.cmp(rhs)
38 }
39}
40
41impl CaseSensitivity for CaseInsensitive {
42 #[inline]
43 fn eq(lhs: &str, rhs: &str) -> bool {
44 lhs.eq_ignore_case(rhs)
45 }
46
47 #[inline]
48 fn cmp(lhs: &str, rhs: &str) -> Ordering {
49 lhs.cmp_ignore_case(rhs)
50 }
51}
52
53pub trait WrapCased {
58 type Wrapper<S: CaseSensitivity>;
60
61 fn case_sensitive(self) -> Self::Wrapper<CaseSensitive>;
62 fn case_insensitive(self) -> Self::Wrapper<CaseInsensitive>;
63}