1use crate::Pipe;
2use crate::case;
3
4pub struct Upper;
8
9impl Pipe for Upper {
10 type Input = String;
11 type Output = proc_macro2::Ident;
12
13 fn pipe(&self, input: String) -> proc_macro2::Ident {
14 proc_macro2::Ident::new(&input.to_uppercase(), proc_macro2::Span::call_site())
15 }
16}
17
18pub struct Lower;
22
23impl Pipe for Lower {
24 type Input = String;
25 type Output = proc_macro2::Ident;
26
27 fn pipe(&self, input: String) -> proc_macro2::Ident {
28 proc_macro2::Ident::new(&input.to_lowercase(), proc_macro2::Span::call_site())
29 }
30}
31
32pub struct Snake;
36
37impl Pipe for Snake {
38 type Input = String;
39 type Output = proc_macro2::Ident;
40
41 fn pipe(&self, input: String) -> proc_macro2::Ident {
42 proc_macro2::Ident::new(&case::to_snake(&input), proc_macro2::Span::call_site())
43 }
44}
45
46pub struct Camel;
50
51impl Pipe for Camel {
52 type Input = String;
53 type Output = proc_macro2::Ident;
54
55 fn pipe(&self, input: String) -> proc_macro2::Ident {
56 proc_macro2::Ident::new(&case::to_camel(&input), proc_macro2::Span::call_site())
57 }
58}
59
60pub struct Pascal;
64
65impl Pipe for Pascal {
66 type Input = String;
67 type Output = proc_macro2::Ident;
68
69 fn pipe(&self, input: String) -> proc_macro2::Ident {
70 proc_macro2::Ident::new(&case::to_pascal(&input), proc_macro2::Span::call_site())
71 }
72}
73
74pub struct Kebab;
81
82impl Pipe for Kebab {
83 type Input = String;
84 type Output = syn::LitStr;
85
86 fn pipe(&self, input: String) -> syn::LitStr {
87 syn::LitStr::new(&case::to_kebab(&input), proc_macro2::Span::call_site())
88 }
89}
90
91pub struct Screaming;
95
96impl Pipe for Screaming {
97 type Input = String;
98 type Output = proc_macro2::Ident;
99
100 fn pipe(&self, input: String) -> proc_macro2::Ident {
101 proc_macro2::Ident::new(&case::to_screaming(&input), proc_macro2::Span::call_site())
102 }
103}
104
105pub struct Ident(pub &'static str);
111
112impl Pipe for Ident {
113 type Input = String;
114 type Output = proc_macro2::Ident;
115
116 fn pipe(&self, input: String) -> proc_macro2::Ident {
117 let formatted = self.0.replace("{}", &input);
118 proc_macro2::Ident::new(&formatted, proc_macro2::Span::call_site())
119 }
120}
121
122pub struct Fmt(pub &'static str);
128
129impl Pipe for Fmt {
130 type Input = String;
131 type Output = syn::LitStr;
132
133 fn pipe(&self, input: String) -> syn::LitStr {
134 let formatted = self.0.replace("{}", &input);
135 syn::LitStr::new(&formatted, proc_macro2::Span::call_site())
136 }
137}
138
139pub struct Str;
140
141impl Pipe for Str {
142 type Input = String;
143 type Output = syn::LitStr;
144
145 fn pipe(&self, input: String) -> syn::LitStr {
146 syn::LitStr::new(&input, proc_macro2::Span::call_site())
147 }
148}
149
150pub struct Trim;
151
152impl Pipe for Trim {
153 type Input = String;
154 type Output = proc_macro2::Ident;
155
156 fn pipe(&self, input: String) -> proc_macro2::Ident {
157 let trimmed = input.trim_matches('_');
158 proc_macro2::Ident::new(trimmed, proc_macro2::Span::call_site())
159 }
160}
161
162pub struct Plural;
163
164impl Pipe for Plural {
165 type Input = String;
166 type Output = proc_macro2::Ident;
167
168 fn pipe(&self, input: String) -> proc_macro2::Ident {
169 let result = if input.ends_with('s') {
170 format!("{}es", input)
171 } else {
172 format!("{}s", input)
173 };
174 proc_macro2::Ident::new(&result, proc_macro2::Span::call_site())
175 }
176}
177
178pub struct Singular;
179
180impl Pipe for Singular {
181 type Input = String;
182 type Output = proc_macro2::Ident;
183
184 fn pipe(&self, input: String) -> proc_macro2::Ident {
185 let result = if input.ends_with('s') && !input.ends_with("ss") {
186 &input[..input.len() - 1]
187 } else {
188 &input
189 };
190 proc_macro2::Ident::new(result, proc_macro2::Span::call_site())
191 }
192}