Re: [PATCH] rust: bitfield: add conversions to Bounded of matching width
From: Gary Guo
Date: Fri Nov 27 2026 - 15:05:14 EST
On Fri Nov 27, 2026 at 12:05 PM GMT, Alexandre Courbot wrote:
> `From`/`Into` implementations already exist between a bitfield type and
> its storage type, but these are not enough to support nested bitfields,
> since every field is a `Bounded`. This resulted in some ad-hoc
> implementations to enable this kind of declaration:
>
> bitfield! {
> pub struct Version(u8) {
> 7:4 major;
> 3:0 minor;
> }
> }
>
> bitfield! {
> pub struct Id(u16) {
> 15:8 vendor;
> 7:0 version => Version;
> }
> }
>
> Generate these conversions automatically through the `bitfield!` macro,
> as these tend to be useful.
>
> Tyr had such ad-hoc implementations, so remove them to avoid conflicts.
>
> Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>
> ---
> drivers/gpu/drm/tyr/regs.rs | 30 +++++------------
> rust/kernel/bitfield.rs | 82 ++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 89 insertions(+), 23 deletions(-)