1
1
use anyhow:: { bail, Result } ;
2
- use std:: path:: { Path , PathBuf } ;
2
+ use std:: {
3
+ collections:: HashMap ,
4
+ ops:: { Deref , DerefMut } ,
5
+ path:: { Path , PathBuf } ,
6
+ } ;
3
7
4
8
#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
5
9
#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
10
+ #[ non_exhaustive]
6
11
pub struct Config {
7
12
pub target : Target ,
8
13
pub atomics : bool ,
@@ -13,7 +18,6 @@ pub struct Config {
13
18
pub ignore_groups : bool ,
14
19
pub keep_list : bool ,
15
20
pub strict : bool ,
16
- pub pascal_enum_values : bool ,
17
21
pub feature_group : bool ,
18
22
pub feature_peripheral : bool ,
19
23
pub max_cluster_size : bool ,
@@ -135,6 +139,7 @@ pub enum Case {
135
139
#[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
136
140
#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
137
141
pub struct IdentFormat {
142
+ // Ident case. `None` means don't change
138
143
pub case : Option < Case > ,
139
144
pub prefix : String ,
140
145
pub suffix : String ,
@@ -153,8 +158,8 @@ impl IdentFormat {
153
158
self . case = Some ( Case :: Pascal ) ;
154
159
self
155
160
}
156
- pub fn scake_case ( mut self ) -> Self {
157
- self . case = Some ( Case :: Pascal ) ;
161
+ pub fn snake_case ( mut self ) -> Self {
162
+ self . case = Some ( Case :: Snake ) ;
158
163
self
159
164
}
160
165
pub fn prefix ( mut self , prefix : & str ) -> Self {
@@ -169,32 +174,66 @@ impl IdentFormat {
169
174
170
175
#[ derive( Clone , Debug , PartialEq , Eq ) ]
171
176
#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
172
- pub struct IdentFormats {
173
- pub field_reader : IdentFormat ,
174
- pub field_writer : IdentFormat ,
175
- pub enum_name : IdentFormat ,
176
- pub enum_write_name : IdentFormat ,
177
- pub enum_value : IdentFormat ,
178
- pub interrupt : IdentFormat ,
179
- pub cluster : IdentFormat ,
180
- pub register : IdentFormat ,
181
- pub register_spec : IdentFormat ,
182
- pub peripheral : IdentFormat ,
183
- }
177
+ pub struct IdentFormats ( HashMap < String , IdentFormat > ) ;
184
178
185
179
impl Default for IdentFormats {
186
180
fn default ( ) -> Self {
187
- Self {
188
- field_reader : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_R" ) ,
189
- field_writer : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_W" ) ,
190
- enum_name : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_A" ) ,
191
- enum_write_name : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_AW" ) ,
192
- enum_value : IdentFormat :: default ( ) . constant_case ( ) ,
193
- interrupt : IdentFormat :: default ( ) . constant_case ( ) ,
194
- cluster : IdentFormat :: default ( ) . constant_case ( ) ,
195
- register : IdentFormat :: default ( ) . constant_case ( ) ,
196
- register_spec : IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_SPEC" ) ,
197
- peripheral : IdentFormat :: default ( ) . constant_case ( ) ,
198
- }
181
+ let mut map = HashMap :: new ( ) ;
182
+
183
+ map. insert (
184
+ "field_reader" . into ( ) ,
185
+ IdentFormat :: default ( ) . pascal_case ( ) . suffix ( "R" ) ,
186
+ ) ;
187
+ map. insert (
188
+ "field_writer" . into ( ) ,
189
+ IdentFormat :: default ( ) . pascal_case ( ) . suffix ( "W" ) ,
190
+ ) ;
191
+ map. insert ( "enum_name" . into ( ) , IdentFormat :: default ( ) . pascal_case ( ) ) ;
192
+ map. insert (
193
+ "enum_write_name" . into ( ) ,
194
+ IdentFormat :: default ( ) . pascal_case ( ) . suffix ( "WO" ) ,
195
+ ) ;
196
+ map. insert ( "enum_value" . into ( ) , IdentFormat :: default ( ) . pascal_case ( ) ) ;
197
+ map. insert ( "interrupt" . into ( ) , IdentFormat :: default ( ) ) ;
198
+ map. insert ( "cluster" . into ( ) , IdentFormat :: default ( ) . pascal_case ( ) ) ;
199
+ map. insert (
200
+ "cluster_accessor" . into ( ) ,
201
+ IdentFormat :: default ( ) . snake_case ( ) ,
202
+ ) ;
203
+ map. insert ( "cluster_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
204
+ map. insert ( "register" . into ( ) , IdentFormat :: default ( ) . pascal_case ( ) ) ;
205
+ map. insert (
206
+ "register_spec" . into ( ) ,
207
+ IdentFormat :: default ( ) . pascal_case ( ) . suffix ( "Spec" ) ,
208
+ ) ;
209
+ map. insert (
210
+ "register_accessor" . into ( ) ,
211
+ IdentFormat :: default ( ) . snake_case ( ) ,
212
+ ) ;
213
+ map. insert ( "register_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
214
+ map. insert ( "peripheral" . into ( ) , IdentFormat :: default ( ) . pascal_case ( ) ) ;
215
+ map. insert (
216
+ "peripheral_sigleton" . into ( ) ,
217
+ IdentFormat :: default ( ) . snake_case ( ) ,
218
+ ) ;
219
+ map. insert ( "peripheral_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
220
+ map. insert (
221
+ "peripheral_feature" . into ( ) ,
222
+ IdentFormat :: default ( ) . snake_case ( ) ,
223
+ ) ;
224
+
225
+ Self ( map)
226
+ }
227
+ }
228
+
229
+ impl Deref for IdentFormats {
230
+ type Target = HashMap < String , IdentFormat > ;
231
+ fn deref ( & self ) -> & Self :: Target {
232
+ & self . 0
233
+ }
234
+ }
235
+ impl DerefMut for IdentFormats {
236
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
237
+ & mut self . 0
199
238
}
200
239
}
0 commit comments