File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77
88## [ Unreleased]
99
10+ - Yet more clean field ` Debug `
11+
1012## [ v0.33.2] - 2024-05-07
1113
1214- Remove unneeded ` format_args ` in register ` Debug ` impl
Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ pub trait RegisterSpec {
5353/// Raw field type
5454pub trait FieldSpec : Sized {
5555 /// Raw field type (`u8`, `u16`, `u32`, ...).
56- type Ux : Copy + PartialEq + From < Self > ;
56+ type Ux : Copy + core :: fmt :: Debug + PartialEq + From < Self > ;
5757}
5858
5959/// Marker for fields with fixed values
@@ -433,6 +433,12 @@ impl<FI: FieldSpec> FieldReader<FI> {
433433 }
434434}
435435
436+ impl < FI : FieldSpec > core:: fmt:: Debug for FieldReader < FI > {
437+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
438+ core:: fmt:: Debug :: fmt ( & self . bits , f)
439+ }
440+ }
441+
436442impl < FI > PartialEq < FI > for FieldReader < FI >
437443where
438444 FI : FieldSpec + Copy ,
@@ -472,6 +478,12 @@ impl<FI> BitReader<FI> {
472478 }
473479}
474480
481+ impl < FI > core:: fmt:: Debug for BitReader < FI > {
482+ fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
483+ core:: fmt:: Debug :: fmt ( & self . bits , f)
484+ }
485+ }
486+
475487/// Marker for register/field writers which can take any value of specified width
476488pub struct Safe ;
477489/// You should check that value is allowed to pass to register/field writer marked with this
Original file line number Diff line number Diff line change @@ -467,24 +467,22 @@ fn render_register_mod_debug(
467467 Some ( a) => a,
468468 None => access,
469469 } ;
470- let bit_or_bits = if f. bit_width ( ) > 1 { "bits" } else { "bit" } ;
471- let bit_or_bits = syn:: Ident :: new ( bit_or_bits, span) ;
472470 log:: debug!( "register={} field={}" , name, f. name) ;
473471 if field_access. can_read ( ) && f. read_action . is_none ( ) {
474472 if let Field :: Array ( _, de) = & f {
475473 for suffix in de. indexes ( ) {
476474 let f_name_n = field_accessor ( & f. name . expand_dim ( & suffix) , config, span) ;
477475 let f_name_n_s = format ! ( "{f_name_n}" ) ;
478476 r_debug_impl. extend ( quote ! {
479- . field( #f_name_n_s, & self . #f_name_n( ) . #bit_or_bits ( ) )
477+ . field( #f_name_n_s, & self . #f_name_n( ) )
480478 } ) ;
481479 }
482480 } else {
483481 let f_name = f. name . remove_dim ( ) ;
484482 let f_name = field_accessor ( & f_name, config, span) ;
485483 let f_name_s = format ! ( "{f_name}" ) ;
486484 r_debug_impl. extend ( quote ! {
487- . field( #f_name_s, & self . #f_name( ) . #bit_or_bits ( ) )
485+ . field( #f_name_s, & self . #f_name( ) )
488486 } ) ;
489487 }
490488 }
You can’t perform that action at this time.
0 commit comments