Skip to content

Commit 89f41d8

Browse files
committed
improve defmt_bitfields codegen: Use fully qualified trait method syntax
1 parent b074b7f commit 89f41d8

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

bitbybit/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ This version expects arbitrary-int 2.x.
88

99
- Support for signed arbitrary-int integers as field types, e.g. `i3`, `i24`, etc.
1010

11+
### Fixed
12+
13+
- Use fully qualified trait syntax in `defmt_bitfields` macro implementation, avoiding the need
14+
for users to import the `arbitrary_int::traits::Integer` trait for auto-generated code.
15+
1116
## bitbybit 1.4.0
1217

1318
This is the final version to support arbitrary-int 1.x. Future versions will require arbitrary-int 2.x.

bitbybit/src/bitfield/codegen.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,18 @@ pub fn generate_defmt_trait_impl(
609609
quote! { self.raw_value() }
610610
}
611611
_ => match base_data_size.internal {
612-
0..=7 => quote! { self.raw_value().as_u8() },
613-
8..=15 => quote! { self.raw_value().as_u16() },
614-
16..=31 => quote! { self.raw_value().as_u32() },
615-
32..=63 => quote! { self.raw_value().as_u64() },
612+
0..=7 => {
613+
quote! { arbitrary_int::traits::Integer::as_u8(self.raw_value()) }
614+
}
615+
8..=15 => {
616+
quote! { arbitrary_int::traits::Integer::as_u16(self.raw_value()) }
617+
}
618+
16..=31 => {
619+
quote! { arbitrary_int::traits::Integer::as_u32(self.raw_value()) }
620+
}
621+
32..=63 => {
622+
quote! { arbitrary_int::traits::Integer::as_u64(self.raw_value()) }
623+
}
616624
_ => panic!("Unsupported base data size for defmt_bitfields"),
617625
},
618626
}

0 commit comments

Comments
 (0)