naming_conventions/
lib.rs1mod tool;
2
3use regex::Error;
4
5pub mod conventions;
6
7pub use conventions::*;
8
9pub enum CaseName {
10 NoCase,
11 SnakeCase,
12 CamelCase,
13 PascalCase,
14 MacroCase,
15 KebabCase,
16 TrainCase,
17 FlatCase,
18}
19
20pub trait Convention {
21 fn to(&self, string: &str) -> Result<String, Error>;
22 fn is(&self, string: &str) -> Result<bool, Error>;
23}
24
25pub fn get_convention(name: CaseName) -> Box<dyn Convention> {
38 match name {
39 CaseName::NoCase => Box::new(NoCase),
40 CaseName::SnakeCase => Box::new(SnakeCase),
41 CaseName::CamelCase => Box::new(CamelCase),
42 CaseName::PascalCase => Box::new(PascalCase),
43 CaseName::MacroCase => Box::new(MacroCase),
44 CaseName::KebabCase => Box::new(KebabCase),
45 CaseName::FlatCase => Box::new(FlatCase),
46 CaseName::TrainCase => Box::new(TrainCase),
47 }
48}
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 fn init() {
55 dotenv::dotenv().ok();
56 let _ = env_logger::try_init();
57 }
58
59 #[test]
60 fn test_get_convention() {
61 tests::init();
62
63 let no_case = get_convention(CaseName::NoCase);
64
65 assert_eq!(no_case.to("hello, world!").unwrap(), "hello, world!")
66 }
67}