@@ -282,17 +282,17 @@ pub fn fields(
282
282
}
283
283
} ;
284
284
285
+ r_impl_items. extend ( quote ! {
286
+ #[ doc = #description_with_bits]
287
+ #[ inline( always) ]
288
+ pub fn #sc( & self ) -> #_pc_r {
289
+ #_pc_r:: new ( #value )
290
+ }
291
+ } ) ;
292
+
285
293
if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Read ) {
286
294
evs_r = Some ( evs. clone ( ) ) ;
287
295
288
- r_impl_items. extend ( quote ! {
289
- #[ doc = #description_with_bits]
290
- #[ inline( always) ]
291
- pub fn #sc( & self ) -> #_pc_r {
292
- #_pc_r:: new( #value )
293
- }
294
- } ) ;
295
-
296
296
if let Some ( base) = base {
297
297
let pc = base. field . to_sanitized_upper_case ( ) ;
298
298
let base_pc_r = Ident :: new ( & ( pc. clone ( ) + "_A" ) , span) ;
@@ -309,50 +309,50 @@ pub fn fields(
309
309
310
310
add_from_variants ( mod_items, & variants, & pc_r, & fty, & description, rv) ;
311
311
312
- let mut enum_items = vec ! [ ] ;
312
+ let mut enum_items = TokenStream :: new ( ) ;
313
313
314
- let mut arms = variants
315
- . iter ( )
316
- . map ( |v| {
317
- let i = util:: unsuffixed_or_bool ( v. value , width) ;
318
- let pc = & v. pc ;
314
+ let mut arms = TokenStream :: new ( ) ;
315
+ for v in variants. iter ( ) . map ( |v| {
316
+ let i = util:: unsuffixed_or_bool ( v. value , width) ;
317
+ let pc = & v. pc ;
319
318
320
- if has_reserved_variant {
321
- quote ! { #i => Val ( #pc_r:: #pc) }
322
- } else {
323
- quote ! { #i => #pc_r:: #pc }
324
- }
325
- } )
326
- . collect :: < Vec < _ > > ( ) ;
319
+ if has_reserved_variant {
320
+ quote ! { #i => Val ( #pc_r:: #pc) , }
321
+ } else {
322
+ quote ! { #i => #pc_r:: #pc, }
323
+ }
324
+ } ) {
325
+ arms. extend ( v) ;
326
+ }
327
327
328
328
if has_reserved_variant {
329
- arms. push ( quote ! {
330
- i => Res ( i)
329
+ arms. extend ( quote ! {
330
+ i => Res ( i) ,
331
331
} ) ;
332
332
} else if 1 << width. to_ty_width ( ) ? != variants. len ( ) {
333
- arms. push ( quote ! {
334
- _ => unreachable!( )
333
+ arms. extend ( quote ! {
334
+ _ => unreachable!( ) ,
335
335
} ) ;
336
336
}
337
337
338
338
if has_reserved_variant {
339
- enum_items. push ( quote ! {
339
+ enum_items. extend ( quote ! {
340
340
///Get enumerated values variant
341
341
#[ inline( always) ]
342
342
pub fn variant( & self ) -> crate :: Variant <#fty, #pc_r> {
343
343
use crate :: Variant :: * ;
344
344
match self . bits {
345
- #( # arms) , *
345
+ #arms
346
346
}
347
347
}
348
348
} ) ;
349
349
} else {
350
- enum_items. push ( quote ! {
350
+ enum_items. extend ( quote ! {
351
351
///Get enumerated values variant
352
352
#[ inline( always) ]
353
353
pub fn variant( & self ) -> #pc_r {
354
354
match self . bits {
355
- #( # arms) , *
355
+ #arms
356
356
}
357
357
}
358
358
} ) ;
@@ -372,7 +372,7 @@ pub fn fields(
372
372
) ;
373
373
374
374
let doc = format ! ( "Checks if the value of the field is `{}`" , pc) ;
375
- enum_items. push ( quote ! {
375
+ enum_items. extend ( quote ! {
376
376
#[ doc = #doc]
377
377
#[ inline( always) ]
378
378
pub fn #is_variant( & self ) -> bool {
@@ -386,19 +386,11 @@ pub fn fields(
386
386
#[ doc = #doc]
387
387
pub type #_pc_r = crate :: R <#fty, #pc_r>;
388
388
impl #_pc_r {
389
- #( # enum_items) *
389
+ #enum_items
390
390
}
391
391
} ) ;
392
392
}
393
393
} else {
394
- r_impl_items. extend ( quote ! {
395
- #[ doc = #description_with_bits]
396
- #[ inline( always) ]
397
- pub fn #sc( & self ) -> #_pc_r {
398
- #_pc_r:: new ( #value )
399
- }
400
- } ) ;
401
-
402
394
let doc = format ! ( "Reader of field `{}`" , f. name) ;
403
395
mod_items. extend ( quote ! {
404
396
#[ doc = #doc]
@@ -411,7 +403,7 @@ pub fn fields(
411
403
let new_pc_w = Ident :: new ( & ( pc. clone ( ) + "_AW" ) , span) ;
412
404
let _pc_w = Ident :: new ( & ( pc. clone ( ) + "_W" ) , span) ;
413
405
414
- let mut proxy_items = vec ! [ ] ;
406
+ let mut proxy_items = TokenStream :: new ( ) ;
415
407
let mut unsafety = unsafety ( f. write_constraint . as_ref ( ) , width) ;
416
408
417
409
if let Some ( ( evs, base) ) = lookup_filter ( & lookup_results, Usage :: Write ) {
@@ -432,7 +424,7 @@ pub fn fields(
432
424
}
433
425
}
434
426
435
- proxy_items. push ( quote ! {
427
+ proxy_items. extend ( quote ! {
436
428
///Writes `variant` to the field
437
429
#[ inline( always) ]
438
430
pub fn variant( self , variant: #pc_w) -> & ' a mut W {
@@ -447,7 +439,7 @@ pub fn fields(
447
439
let sc = & v. sc ;
448
440
449
441
let doc = util:: escape_brackets ( util:: respace ( & v. doc ) . as_ref ( ) ) ;
450
- proxy_items. push ( quote ! {
442
+ proxy_items. extend ( quote ! {
451
443
#[ doc = #doc]
452
444
#[ inline( always) ]
453
445
pub fn #sc( self ) -> & ' a mut W {
@@ -458,7 +450,7 @@ pub fn fields(
458
450
}
459
451
460
452
if width == 1 {
461
- proxy_items. push ( quote ! {
453
+ proxy_items. extend ( quote ! {
462
454
///Sets the field bit
463
455
#[ inline( always) ]
464
456
pub #unsafety fn set_bit( self ) -> & ' a mut W {
@@ -473,7 +465,7 @@ pub fn fields(
473
465
} ) ;
474
466
}
475
467
476
- proxy_items. push ( if offset != 0 {
468
+ proxy_items. extend ( if offset != 0 {
477
469
let offset = & util:: unsuffixed ( offset) ;
478
470
quote ! {
479
471
///Writes raw bits to the field
@@ -502,7 +494,7 @@ pub fn fields(
502
494
}
503
495
504
496
impl <' a> #_pc_w<' a> {
505
- #( # proxy_items) *
497
+ #proxy_items
506
498
}
507
499
} ) ;
508
500
@@ -587,18 +579,18 @@ fn add_from_variants(
587
579
( quote ! { #[ repr( #fty) ] } , quote ! { variant as _ } )
588
580
} ;
589
581
590
- let vars = variants
591
- . iter ( )
592
- . map ( |v| {
593
- let desc = util :: escape_brackets ( & format ! ( "{}: {}" , v . value , v . doc ) ) ;
594
- let pcv = & v . pc ;
595
- let pcval = & util :: unsuffixed ( v . value ) ;
596
- quote ! {
597
- # [ doc = #desc ]
598
- #pcv = #pcval
599
- }
600
- } )
601
- . collect :: < Vec < _ > > ( ) ;
582
+ let mut vars = TokenStream :: new ( ) ;
583
+ for v in variants . iter ( ) . map ( |v| {
584
+ let desc = util :: escape_brackets ( & format ! ( "{}: {}" , v . value , v . doc ) ) ;
585
+ let pcv = & v . pc ;
586
+ let pcval = & util :: unsuffixed ( v . value ) ;
587
+ quote ! {
588
+ # [ doc = #desc ]
589
+ #pcv = #pcval ,
590
+ }
591
+ } ) {
592
+ vars . extend ( v ) ;
593
+ }
602
594
603
595
let desc = if let Some ( rv) = reset_value {
604
596
format ! ( "{}\n \n Value on reset: {}" , desc, rv)
@@ -611,7 +603,7 @@ fn add_from_variants(
611
603
#[ derive( Clone , Copy , Debug , PartialEq ) ]
612
604
#repr
613
605
pub enum #pc {
614
- #( # vars) , *
606
+ #vars
615
607
}
616
608
impl From <#pc> for #fty {
617
609
#[ inline( always) ]
0 commit comments