Skip to content

rust: macros: Add derive Display for enums

Maurice Hieronymus dri-devel lkml nouveau rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v2 Latest2 patches 10 repliesIn review

Changes in v2 from the cover letter

- Instead of using the name() method with lowercase strings, implement a proper derive macro using syn as suggested by the reviewer
- The derive macro outputs the exact variant name as written (case-preserved)
- Supports all enum variant types: unit, tuple, and struct variants

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust: macros: Add derive Display for enumsrust/macros/display.rs rust/macros/lib.rs+94 -010 replies
2/2gpu: nova-core: Use derive Display for Chipset enumdrivers/gpu/nova-core/gpu.rs+2 -150 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] rust: macros: Add derive Display for enums

This patch series adds a derive macro for implementing kernel::fmt::Display on enums using the syn crate, and then applies it to the Chipset enum in the nova-core driver.

Maurice Hieronymus (2):
rust: macros: Add derive Display for enums
gpu: nova-core: Use derive Display for Chipset enum

 drivers/gpu/nova-core/gpu.rs | 17 ++----------
 rust/macros/display.rs       | 52 ++++++++++++++++++++++++++++++++++++
 rust/macros/lib.rs           | 42 +++++++++++++++++++++++++++++
 3 files changed, 96 insertions(+), 15 deletions(-)
 create mode 100644 rust/macros/display.rs

---
v1: https://lore.kernel.org/all/[email protected]/

Changes since v1:
- Instead of using the name() method with lowercase strings, implement a proper derive macro using syn as suggested by the reviewer
- The derive macro outputs the exact variant name as written (case-preserved)
- Supports all enum variant types: unit, tuple, and struct variants

base-commit: f8f9c1f4d0c7a64600e2ca312dec824a0bc2f1da

Signature · 1 line
2.51.2