@@ -16,10 +16,7 @@ fn camel_to_snake_case(variable_name: &str) -> String {
1616 for c in variable_name. chars ( ) {
1717 if c. is_uppercase ( ) {
1818 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 ( ) ) ;
2320 } else {
2421 snake_case_parts. push ( c. to_lowercase ( ) . to_string ( ) ) ;
2522 }
@@ -80,9 +77,7 @@ impl EnumBindGenerator {
8077 } )
8178 }
8279
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 > {
8681 raw_types
8782 . into_iter ( )
8883 . map ( |( name, raw_type, doc_str) | CustomEnumType {
@@ -129,17 +124,12 @@ impl EnumBindGenerator {
129124 continue ;
130125 }
131126
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 ( ';' ) ;
135128
136129 let mut parts = definition. split ( ": Self = " ) ;
137130
138131 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 ( ')' ) ;
143133
144134 let docs = if docs. is_empty ( ) {
145135 None
@@ -169,14 +159,11 @@ impl EnumBindGenerator {
169159 let union_end_definition = "}\n " ;
170160 let union_end = contents[ union_start..] . find ( union_end_definition) . unwrap ( ) ;
171161
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 ( ) ] ;
174164
175165 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 ( ',' ) ;
180167
181168 if line_trim. is_empty ( ) {
182169 variable. value = None ;
@@ -185,9 +172,7 @@ impl EnumBindGenerator {
185172
186173 variable. snake_case_name = camel_to_snake_case ( variable. name . as_str ( ) ) ;
187174
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>)" ) ;
191176 variable. value = Some ( new_type. to_string ( ) ) ;
192177 }
193178
@@ -204,11 +189,7 @@ impl EnumBindGenerator {
204189
205190 for variable_info in & self . types {
206191 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) ;
212193 }
213194
214195 if self . types . len ( ) != usize:: from ( u8:: MAX ) {
@@ -256,10 +237,7 @@ impl Generator for EnumBindGenerator {
256237 contents = contents. replace ( "\r \n " , "\n " ) ;
257238 }
258239
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" ) ;
263241
264242 contents = contents. replace (
265243 "#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]\n " ,
@@ -288,14 +266,8 @@ impl Generator for EnumBindGenerator {
288266
289267 fn generate_definition ( & mut self ) {
290268 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)]" ) ;
299271 write_fmt ! ( self , "pub enum {} {{" , self . struct_name) ;
300272 write_str ! ( self , " #[default]" ) ;
301273
@@ -309,17 +281,8 @@ impl Generator for EnumBindGenerator {
309281 }
310282
311283 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) ;
323286 write_str ! ( self , " match flat_t {" ) ;
324287
325288 for variable_info in & self . types {
@@ -332,11 +295,7 @@ impl Generator for EnumBindGenerator {
332295 ) ;
333296 }
334297
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( ) ) ;
340299
341300 write_str ! ( self , " }" ) ;
342301 write_str ! ( self , " }" ) ;
@@ -345,17 +304,8 @@ impl Generator for EnumBindGenerator {
345304 }
346305
347306 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) ;
359309 write_str ! ( self , " match *py_type {" ) ;
360310
361311 for variable_info in & self . types {
0 commit comments