11use anyhow:: { bail, Result } ;
2- use std:: path:: { Path , PathBuf } ;
2+ use std:: {
3+ collections:: HashMap ,
4+ ops:: { Deref , DerefMut } ,
5+ path:: { Path , PathBuf } ,
6+ } ;
37
48#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
59#[ derive( Clone , PartialEq , Eq , Debug , Default ) ]
10+ #[ non_exhaustive]
611pub struct Config {
712 pub target : Target ,
813 pub atomics : bool ,
@@ -13,7 +18,6 @@ pub struct Config {
1318 pub ignore_groups : bool ,
1419 pub keep_list : bool ,
1520 pub strict : bool ,
16- pub pascal_enum_values : bool ,
1721 pub feature_group : bool ,
1822 pub feature_peripheral : bool ,
1923 pub max_cluster_size : bool ,
@@ -135,6 +139,7 @@ pub enum Case {
135139#[ derive( Clone , Debug , Default , PartialEq , Eq ) ]
136140#[ cfg_attr( feature = "serde" , derive( serde:: Deserialize ) , serde( default ) ) ]
137141pub struct IdentFormat {
142+ // Ident case. `None` means don't change
138143 pub case : Option < Case > ,
139144 pub prefix : String ,
140145 pub suffix : String ,
@@ -153,8 +158,8 @@ impl IdentFormat {
153158 self . case = Some ( Case :: Pascal ) ;
154159 self
155160 }
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 ) ;
158163 self
159164 }
160165 pub fn prefix ( mut self , prefix : & str ) -> Self {
@@ -169,32 +174,74 @@ impl IdentFormat {
169174
170175#[ derive( Clone , Debug , PartialEq , Eq ) ]
171176#[ 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 > ) ;
184178
185179impl Default for IdentFormats {
186180 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 ( "field_accessor" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
184+ map. insert (
185+ "field_reader" . into ( ) ,
186+ IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_R" ) ,
187+ ) ;
188+ map. insert (
189+ "field_writer" . into ( ) ,
190+ IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_W" ) ,
191+ ) ;
192+ map. insert (
193+ "enum_name" . into ( ) ,
194+ IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_A" ) ,
195+ ) ;
196+ map. insert (
197+ "enum_write_name" . into ( ) ,
198+ IdentFormat :: default ( ) . constant_case ( ) . suffix ( "_AW" ) ,
199+ ) ;
200+ map. insert ( "enum_value" . into ( ) , IdentFormat :: default ( ) . constant_case ( ) ) ;
201+ map. insert (
202+ "enum_value_accessor" . into ( ) ,
203+ IdentFormat :: default ( ) . snake_case ( ) ,
204+ ) ;
205+ map. insert ( "interrupt" . into ( ) , IdentFormat :: default ( ) . constant_case ( ) ) ;
206+ map. insert ( "cluster" . into ( ) , IdentFormat :: default ( ) . constant_case ( ) ) ;
207+ map. insert (
208+ "cluster_accessor" . into ( ) ,
209+ IdentFormat :: default ( ) . snake_case ( ) ,
210+ ) ;
211+ map. insert ( "cluster_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
212+ map. insert ( "register" . into ( ) , IdentFormat :: default ( ) . constant_case ( ) ) ;
213+ map. insert (
214+ "register_spec" . into ( ) ,
215+ IdentFormat :: default ( ) . pascal_case ( ) . suffix ( "_SPEC" ) ,
216+ ) ;
217+ map. insert (
218+ "register_accessor" . into ( ) ,
219+ IdentFormat :: default ( ) . snake_case ( ) ,
220+ ) ;
221+ map. insert ( "register_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
222+ map. insert ( "peripheral" . into ( ) , IdentFormat :: default ( ) . constant_case ( ) ) ;
223+ map. insert (
224+ "peripheral_singleton" . into ( ) ,
225+ IdentFormat :: default ( ) . constant_case ( ) ,
226+ ) ;
227+ map. insert ( "peripheral_mod" . into ( ) , IdentFormat :: default ( ) . snake_case ( ) ) ;
228+ map. insert (
229+ "peripheral_feature" . into ( ) ,
230+ IdentFormat :: default ( ) . snake_case ( ) ,
231+ ) ;
232+
233+ Self ( map)
234+ }
235+ }
236+
237+ impl Deref for IdentFormats {
238+ type Target = HashMap < String , IdentFormat > ;
239+ fn deref ( & self ) -> & Self :: Target {
240+ & self . 0
241+ }
242+ }
243+ impl DerefMut for IdentFormats {
244+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
245+ & mut self . 0
199246 }
200247}
0 commit comments