From b4543efaeb26680d4fe9385b1fcab98bf9914606 Mon Sep 17 00:00:00 2001 From: Overlord Date: Thu, 5 Mar 2026 21:32:37 +0100 Subject: [PATCH] Implement `Display` trait for `Target` in `pmp-macro-misc` to enhance flag formatting and readability --- .../crates/pmp-macro-misc/src/target.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/pmp-macro/crates/pmp-macro-misc/src/target.rs b/crates/pmp-macro/crates/pmp-macro-misc/src/target.rs index 134513a..13e939c 100644 --- a/crates/pmp-macro/crates/pmp-macro-misc/src/target.rs +++ b/crates/pmp-macro/crates/pmp-macro-misc/src/target.rs @@ -1,3 +1,4 @@ +use std::fmt::{ Display, Formatter }; use bitflags::bitflags; bitflags! @@ -37,3 +38,38 @@ bitflags! const ALL = u16::MAX; } } + +impl Display for Target +{ + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result + { + let mut first = true; + + macro_rules! write_flag + { + ($flag:ident) => + { + if self.contains(Target::$flag) + { + if !first { write!(f, " | ")?; } + write!(f, "Target::{}", stringify!($flag))?; + first = false; + } + }; + } + + write_flag!(CLASS); + write_flag!(INTERFACE); + write_flag!(TRAIT); + write_flag!(ENUM); + write_flag!(METHOD); + write_flag!(FUNCTION); + write_flag!(PROPERTY); + write_flag!(CONSTANT); + write_flag!(PARAMETER); + + if first { write!(f, "Target::ALL")?; } + + Ok(()) + } +}