Skip to content

Commit

Permalink
Add custom debug impl for Capabilities<Flag> (#2186)
Browse files Browse the repository at this point in the history
* custom debug impl

* just the flag name

* core debug

* no std

* this is it
  • Loading branch information
Alex6323 committed Mar 19, 2024
1 parent 4fdf8ea commit 67e9a66
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sdk/src/types/block/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<Infallible> for CapabilityError {
}

/// A list of bitflags that represent capabilities.
#[derive(Debug, Deref)]
#[derive(Deref)]
#[repr(transparent)]
pub struct Capabilities<Flag> {
#[deref]
Expand All @@ -58,6 +58,12 @@ impl<Flag> Capabilities<Flag> {
}
}

impl<Flag: CapabilityFlag> core::fmt::Debug for Capabilities<Flag> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_list().entries(self.capabilities_iter()).finish()
}
}

impl<Flag: CapabilityFlag> Capabilities<Flag> {
/// Try to create capabilities from serialized bytes. Bytes with trailing zeroes are invalid.
pub fn from_bytes(bytes: impl Into<Box<[u8]>>) -> Result<Self, CapabilityError> {
Expand Down Expand Up @@ -234,7 +240,7 @@ impl<Flag: 'static + CapabilityFlag> Packable for Capabilities<Flag> {
}
}

pub trait CapabilityFlag {
pub trait CapabilityFlag: core::fmt::Debug {
type Iterator: Iterator<Item = Self>;

/// Converts the flag into the byte representation.
Expand Down

0 comments on commit 67e9a66

Please sign in to comment.