@@ -16,10 +16,7 @@ fn camel_to_snake_case(variable_name: &str) -> String {
16
16
for c in variable_name. chars ( ) {
17
17
if c. is_uppercase ( ) {
18
18
if last_was_uppercase {
19
- snake_case_parts
20
- . last_mut ( )
21
- . unwrap ( )
22
- . push ( c. to_lowercase ( ) . next ( ) . unwrap ( ) ) ;
19
+ snake_case_parts. last_mut ( ) . unwrap ( ) . push ( c. to_lowercase ( ) . next ( ) . unwrap ( ) ) ;
23
20
} else {
24
21
snake_case_parts. push ( c. to_lowercase ( ) . to_string ( ) ) ;
25
22
}
@@ -80,9 +77,7 @@ impl EnumBindGenerator {
80
77
} )
81
78
}
82
79
83
- pub fn raw_types_to_custom (
84
- raw_types : Vec < ( & str , & str , Option < Vec < String > > ) > ,
85
- ) -> Vec < CustomEnumType > {
80
+ pub fn raw_types_to_custom ( raw_types : Vec < ( & str , & str , Option < Vec < String > > ) > ) -> Vec < CustomEnumType > {
86
81
raw_types
87
82
. into_iter ( )
88
83
. map ( |( name, raw_type, doc_str) | CustomEnumType {
@@ -129,17 +124,12 @@ impl EnumBindGenerator {
129
124
continue ;
130
125
}
131
126
132
- let definition = line_trim
133
- . trim_start_matches ( "pub const " )
134
- . trim_end_matches ( ';' ) ;
127
+ let definition = line_trim. trim_start_matches ( "pub const " ) . trim_end_matches ( ';' ) ;
135
128
136
129
let mut parts = definition. split ( ": Self = " ) ;
137
130
138
131
let variable_name = parts. next ( ) ?;
139
- let variable_value = parts
140
- . next ( ) ?
141
- . trim_start_matches ( "Self(" )
142
- . trim_end_matches ( ')' ) ;
132
+ let variable_value = parts. next ( ) ?. trim_start_matches ( "Self(" ) . trim_end_matches ( ')' ) ;
143
133
144
134
let docs = if docs. is_empty ( ) {
145
135
None
@@ -169,14 +159,11 @@ impl EnumBindGenerator {
169
159
let union_end_definition = "}\n " ;
170
160
let union_end = contents[ union_start..] . find ( union_end_definition) . unwrap ( ) ;
171
161
172
- let union_definition = & contents [ union_start + union_definition . len ( )
173
- ..union_start + union_end - union_end_definition. len ( ) ] ;
162
+ let union_definition =
163
+ & contents [ union_start + union_definition . len ( ) ..union_start + union_end - union_end_definition. len ( ) ] ;
174
164
175
165
for ( line, variable) in union_definition. split ( '\n' ) . zip ( & mut custom_types) {
176
- let line_trim = line
177
- . trim ( )
178
- . trim_start_matches ( & variable. name )
179
- . trim_end_matches ( ',' ) ;
166
+ let line_trim = line. trim ( ) . trim_start_matches ( & variable. name ) . trim_end_matches ( ',' ) ;
180
167
181
168
if line_trim. is_empty ( ) {
182
169
variable. value = None ;
@@ -185,9 +172,7 @@ impl EnumBindGenerator {
185
172
186
173
variable. snake_case_name = camel_to_snake_case ( variable. name . as_str ( ) ) ;
187
174
188
- let new_type = line_trim
189
- . trim_start_matches ( "(Box<" )
190
- . trim_end_matches ( "T>)" ) ;
175
+ let new_type = line_trim. trim_start_matches ( "(Box<" ) . trim_end_matches ( "T>)" ) ;
191
176
variable. value = Some ( new_type. to_string ( ) ) ;
192
177
}
193
178
@@ -204,11 +189,7 @@ impl EnumBindGenerator {
204
189
205
190
for variable_info in & self . types {
206
191
let variable_name = variable_info. name . as_str ( ) ;
207
- write_fmt ! (
208
- self ,
209
- " {} => Ok(Self::{variable_name})," ,
210
- variable_info. raw_type
211
- ) ;
192
+ write_fmt ! ( self , " {} => Ok(Self::{variable_name})," , variable_info. raw_type) ;
212
193
}
213
194
214
195
if self . types . len ( ) != usize:: from ( u8:: MAX ) {
@@ -256,10 +237,7 @@ impl Generator for EnumBindGenerator {
256
237
contents = contents. replace ( "\r \n " , "\n " ) ;
257
238
}
258
239
259
- contents = contents. replace (
260
- "use self::flatbuffers" ,
261
- "use get_size::GetSize;\n use self::flatbuffers" ,
262
- ) ;
240
+ contents = contents. replace ( "use self::flatbuffers" , "use get_size::GetSize;\n use self::flatbuffers" ) ;
263
241
264
242
contents = contents. replace (
265
243
"#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]\n " ,
@@ -288,14 +266,8 @@ impl Generator for EnumBindGenerator {
288
266
289
267
fn generate_definition ( & mut self ) {
290
268
write_str ! ( self , "#[allow(non_camel_case_types)]" ) ;
291
- write_str ! (
292
- self ,
293
- "#[pyclass(module = \" rlbot_flatbuffers\" , frozen, hash, eq, eq_int)]"
294
- ) ;
295
- write_str ! (
296
- self ,
297
- "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]"
298
- ) ;
269
+ write_str ! ( self , "#[pyclass(module = \" rlbot_flatbuffers\" , frozen, hash, eq, eq_int)]" ) ;
270
+ write_str ! ( self , "#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]" ) ;
299
271
write_fmt ! ( self , "pub enum {} {{" , self . struct_name) ;
300
272
write_str ! ( self , " #[default]" ) ;
301
273
@@ -309,17 +281,8 @@ impl Generator for EnumBindGenerator {
309
281
}
310
282
311
283
fn generate_from_flat_impls ( & mut self ) {
312
- write_fmt ! (
313
- self ,
314
- "impl From<flat::{}> for {} {{" ,
315
- self . struct_name,
316
- self . struct_name
317
- ) ;
318
- write_fmt ! (
319
- self ,
320
- " fn from(flat_t: flat::{}) -> Self {{" ,
321
- self . struct_name
322
- ) ;
284
+ write_fmt ! ( self , "impl From<flat::{}> for {} {{" , self . struct_name, self . struct_name) ;
285
+ write_fmt ! ( self , " fn from(flat_t: flat::{}) -> Self {{" , self . struct_name) ;
323
286
write_str ! ( self , " match flat_t {" ) ;
324
287
325
288
for variable_info in & self . types {
@@ -332,11 +295,7 @@ impl Generator for EnumBindGenerator {
332
295
) ;
333
296
}
334
297
335
- write_fmt ! (
336
- self ,
337
- " _ => Self::{}," ,
338
- self . types. last( ) . unwrap( ) . name. as_str( )
339
- ) ;
298
+ write_fmt ! ( self , " _ => Self::{}," , self . types. last( ) . unwrap( ) . name. as_str( ) ) ;
340
299
341
300
write_str ! ( self , " }" ) ;
342
301
write_str ! ( self , " }" ) ;
@@ -345,17 +304,8 @@ impl Generator for EnumBindGenerator {
345
304
}
346
305
347
306
fn generate_to_flat_impls ( & mut self ) {
348
- write_fmt ! (
349
- self ,
350
- "impl From<&{}> for flat::{} {{" ,
351
- self . struct_name,
352
- self . struct_name
353
- ) ;
354
- write_fmt ! (
355
- self ,
356
- " fn from(py_type: &{}) -> Self {{" ,
357
- self . struct_name
358
- ) ;
307
+ write_fmt ! ( self , "impl From<&{}> for flat::{} {{" , self . struct_name, self . struct_name) ;
308
+ write_fmt ! ( self , " fn from(py_type: &{}) -> Self {{" , self . struct_name) ;
359
309
write_str ! ( self , " match *py_type {" ) ;
360
310
361
311
for variable_info in & self . types {
0 commit comments