1use derive_more::Display;
2
3mod constant;
4mod snake;
5mod title;
6
7#[derive(Clone, Copy, Debug, Display)]
16pub enum Case {
17 Camel,
18 Constant, Kebab,
20 Lower,
21 Sentence,
22 Snake,
23 Title,
24 Upper,
25 UpperCamel, UpperSnake, UpperKebab, }
29
30pub trait Casing<T: std::fmt::Display> {
35 fn to_case(&self, case: Case) -> String;
36 fn is_case(&self, case: Case) -> bool;
37}
38
39impl<T: std::fmt::Display> Casing<T> for T
40where
41 String: PartialEq<T>,
42{
43 fn to_case(&self, case: Case) -> String {
47 use convert_case as cc;
48 let s = &self.to_string();
49
50 match case {
51 Case::Lower => s.to_lowercase(),
53 Case::Upper => s.to_uppercase(),
54
55 Case::Title => title::to_title_case(s),
57 Case::Snake => snake::to_snake_case(s),
58 Case::UpperSnake => snake::to_snake_case(s).to_uppercase(),
59 Case::Constant => constant::to_constant_case(s).to_uppercase(),
60
61 Case::Camel => cc::Casing::to_case(s, cc::Case::Camel),
63 Case::Kebab => cc::Casing::to_case(s, cc::Case::Kebab),
64 Case::Sentence => cc::Casing::to_case(s, cc::Case::Sentence),
65 Case::UpperCamel => cc::Casing::to_case(s, cc::Case::UpperCamel),
66 Case::UpperKebab => cc::Casing::to_case(s, cc::Case::Kebab).to_uppercase(),
67 }
68 }
69
70 fn is_case(&self, case: Case) -> bool {
72 &self.to_case(case) == self
73 }
74}