File tree 3 files changed +17
-5
lines changed
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/).
7
7
8
8
## [ Unreleased]
9
9
10
+ - Yet more clean field ` Debug `
11
+
10
12
## [ v0.33.2] - 2024-05-07
11
13
12
14
- 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 {
53
53
/// Raw field type
54
54
pub trait FieldSpec : Sized {
55
55
/// Raw field type (`u8`, `u16`, `u32`, ...).
56
- type Ux : Copy + PartialEq + From < Self > ;
56
+ type Ux : Copy + core :: fmt :: Debug + PartialEq + From < Self > ;
57
57
}
58
58
59
59
/// Marker for fields with fixed values
@@ -433,6 +433,12 @@ impl<FI: FieldSpec> FieldReader<FI> {
433
433
}
434
434
}
435
435
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
+
436
442
impl < FI > PartialEq < FI > for FieldReader < FI >
437
443
where
438
444
FI : FieldSpec + Copy ,
@@ -472,6 +478,12 @@ impl<FI> BitReader<FI> {
472
478
}
473
479
}
474
480
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
+
475
487
/// Marker for register/field writers which can take any value of specified width
476
488
pub struct Safe ;
477
489
/// 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(
467
467
Some ( a) => a,
468
468
None => access,
469
469
} ;
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) ;
472
470
log:: debug!( "register={} field={}" , name, f. name) ;
473
471
if field_access. can_read ( ) && f. read_action . is_none ( ) {
474
472
if let Field :: Array ( _, de) = & f {
475
473
for suffix in de. indexes ( ) {
476
474
let f_name_n = field_accessor ( & f. name . expand_dim ( & suffix) , config, span) ;
477
475
let f_name_n_s = format ! ( "{f_name_n}" ) ;
478
476
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( ) )
480
478
} ) ;
481
479
}
482
480
} else {
483
481
let f_name = f. name . remove_dim ( ) ;
484
482
let f_name = field_accessor ( & f_name, config, span) ;
485
483
let f_name_s = format ! ( "{f_name}" ) ;
486
484
r_debug_impl. extend ( quote ! {
487
- . field( #f_name_s, & self . #f_name( ) . #bit_or_bits ( ) )
485
+ . field( #f_name_s, & self . #f_name( ) )
488
486
} ) ;
489
487
}
490
488
}
You can’t perform that action at this time.
0 commit comments