1
1
use std:: borrow:: Cow ;
2
2
3
- use inflections :: Inflect ;
3
+ use crate :: quote :: { ToTokens , TokenStreamExt } ;
4
4
use crate :: svd:: { Access , Cluster , Register , RegisterCluster } ;
5
- use proc_macro2 :: { TokenStream , Ident , Span , Literal } ;
6
- use crate :: quote :: { TokenStreamExt , ToTokens } ;
5
+ use inflections :: Inflect ;
6
+ use proc_macro2 :: { Ident , Literal , Span , TokenStream } ;
7
7
8
8
use crate :: errors:: * ;
9
9
@@ -165,19 +165,19 @@ pub fn escape_brackets(s: &str) -> String {
165
165
if acc == "" {
166
166
x. to_string ( )
167
167
} else if acc. ends_with ( '\\' ) {
168
- acc. to_owned ( ) + "[" + & x. to_string ( )
168
+ acc + "[" + & x. to_string ( )
169
169
} else {
170
- acc. to_owned ( ) + "\\ [" + & x. to_string ( )
170
+ acc + "\\ [" + & x. to_string ( )
171
171
}
172
172
} )
173
173
. split ( ']' )
174
174
. fold ( "" . to_string ( ) , |acc, x| {
175
175
if acc == "" {
176
176
x. to_string ( )
177
177
} else if acc. ends_with ( '\\' ) {
178
- acc. to_owned ( ) + "]" + & x. to_string ( )
178
+ acc + "]" + & x. to_string ( )
179
179
} else {
180
- acc. to_owned ( ) + "\\ ]" + & x. to_string ( )
180
+ acc + "\\ ]" + & x. to_string ( )
181
181
}
182
182
} )
183
183
}
@@ -202,9 +202,15 @@ pub fn access_of(register: &Register) -> Access {
202
202
Access :: ReadOnly
203
203
} else if fields. iter ( ) . all ( |f| f. access == Some ( Access :: WriteOnce ) ) {
204
204
Access :: WriteOnce
205
- } else if fields. iter ( ) . all ( |f| f. access == Some ( Access :: ReadWriteOnce ) ) {
205
+ } else if fields
206
+ . iter ( )
207
+ . all ( |f| f. access == Some ( Access :: ReadWriteOnce ) )
208
+ {
206
209
Access :: ReadWriteOnce
207
- } else if fields. iter ( ) . all ( |f| f. access == Some ( Access :: WriteOnly ) || f. access == Some ( Access :: WriteOnce ) ) {
210
+ } else if fields
211
+ . iter ( )
212
+ . all ( |f| f. access == Some ( Access :: WriteOnly ) || f. access == Some ( Access :: WriteOnce ) )
213
+ {
208
214
Access :: WriteOnly
209
215
} else {
210
216
Access :: ReadWrite
@@ -217,7 +223,12 @@ pub fn access_of(register: &Register) -> Access {
217
223
218
224
/// Turns `n` into an unsuffixed separated hex token
219
225
pub fn hex ( n : u64 ) -> TokenStream {
220
- let ( h4, h3, h2, h1) = ( ( n >> 48 ) & 0xffff , ( n >> 32 ) & 0xffff , ( n >> 16 ) & 0xffff , n & 0xffff ) ;
226
+ let ( h4, h3, h2, h1) = (
227
+ ( n >> 48 ) & 0xffff ,
228
+ ( n >> 32 ) & 0xffff ,
229
+ ( n >> 16 ) & 0xffff ,
230
+ n & 0xffff ,
231
+ ) ;
221
232
syn:: parse_str :: < syn:: Lit > (
222
233
& ( if h4 != 0 {
223
234
format ! ( "0x{:04x}_{:04x}_{:04x}_{:04x}" , h4, h3, h2, h1)
@@ -231,8 +242,10 @@ pub fn hex(n: u64) -> TokenStream {
231
242
format ! ( "0x{:02x}" , h1 & 0xff )
232
243
} else {
233
244
"0" . to_string ( )
234
- } )
235
- ) . unwrap ( ) . into_token_stream ( )
245
+ } ) ,
246
+ )
247
+ . unwrap ( )
248
+ . into_token_stream ( )
236
249
}
237
250
238
251
/// Turns `n` into an unsuffixed token
@@ -245,7 +258,10 @@ pub fn unsuffixed(n: u64) -> TokenStream {
245
258
pub fn unsuffixed_or_bool ( n : u64 , width : u32 ) -> TokenStream {
246
259
if width == 1 {
247
260
let mut t = TokenStream :: new ( ) ;
248
- t. append ( Ident :: new ( if n == 0 { "false" } else { "true" } , Span :: call_site ( ) ) ) ;
261
+ t. append ( Ident :: new (
262
+ if n == 0 { "false" } else { "true" } ,
263
+ Span :: call_site ( ) ,
264
+ ) ) ;
249
265
t
250
266
} else {
251
267
unsuffixed ( n)
@@ -266,10 +282,11 @@ impl U32Ext for u32 {
266
282
9 ..=16 => Ident :: new ( "u16" , span) ,
267
283
17 ..=32 => Ident :: new ( "u32" , span) ,
268
284
33 ..=64 => Ident :: new ( "u64" , span) ,
269
- _ => Err ( format ! (
270
- "can't convert {} bits into a Rust integral type" ,
271
- * self
272
- ) ) ?,
285
+ _ => {
286
+ return Err (
287
+ format ! ( "can't convert {} bits into a Rust integral type" , * self ) . into ( ) ,
288
+ )
289
+ }
273
290
} )
274
291
}
275
292
@@ -280,10 +297,13 @@ impl U32Ext for u32 {
280
297
9 ..=16 => 16 ,
281
298
17 ..=32 => 32 ,
282
299
33 ..=64 => 64 ,
283
- _ => Err ( format ! (
284
- "can't convert {} bits into a Rust integral type width" ,
285
- * self
286
- ) ) ?,
300
+ _ => {
301
+ return Err ( format ! (
302
+ "can't convert {} bits into a Rust integral type width" ,
303
+ * self
304
+ )
305
+ . into ( ) )
306
+ }
287
307
} )
288
308
}
289
309
}
0 commit comments