utils_macros: Implement derive_control_flag

Add a new derive macro 'derive_control_flag' that is used in the next
commit to reimplement how the code deals with Secure Execution control
flags.

It implements Display, IntoEnumIterator and the ControlFlagTrait for
enums using unit variants only.

  /// Trait for control flags that provide bit position information.
  pub trait ControlFlagTrait {
      /// Returns the bit position for this flag.
      fn bit_position(self) -> u8;
  }

Assisted-by: IBM Bob:1.0.4
Signed-off-by: Marc Hartmayer <marc@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Marc Hartmayer
2026-06-22 17:26:31 +02:00
committed by Steffen Eiden
parent 618e22e38b
commit 2d330cd45f
4 changed files with 406 additions and 3 deletions
+17
View File
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: MIT
//
// Copyright IBM Corp.
//! Helper traits and utilities for testing the ControlFlag derive macro.
/// Trait for control flags that provide bit position information.
pub trait ControlFlagTrait {
/// Returns the bit position for this flag.
fn bit_position(self) -> u8;
}
/// Trait for enums that can be iterated over.
pub trait IntoEnumIterator: Sized {
/// Returns an iterator over all variants of the enum.
fn iter() -> impl Iterator<Item = Self>;
}