On Sun Jan 4, 2026 at 9:07 PM CET, Maurice Hieronymus wrote:
> Add a derive macro that implements kernel::fmt::Display for enums.
> The macro outputs the exact variant name as written, preserving case.
>
> This supports all enum variant types: unit, tuple, and struct variants.
> For variants with data, only the variant name is displayed.
I don't think we should be adding this. Display is designed for
user-facing output and so it should always be carefully designed and no
automation should exist for it.
The use-case in the second patch is also much better served by either a
manual match on the enum:
impl fmt::Display for Chipset {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Chipset::Variant => write!(f, "Variant"),
// ...
}
}
}
Or by adding the respective code in the declarative macro already used
to define it.
Cheers,
Benno
> Signed-off-by: Maurice Hieronymus <[email protected]>
> ---
> rust/macros/display.rs | 52 ++++++++++++++++++++++++++++++++++++++++++
> rust/macros/lib.rs | 42 ++++++++++++++++++++++++++++++++++
> 2 files changed, 94 insertions(+)
> create mode 100644 rust/macros/display.rs