Skip to content

Commit

Permalink
impl std::fmt::{Binary, Octal, {Lower,Upper}Hex} for BitFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Aug 25, 2019
1 parent 6cf8c7e commit 6c900d3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions enumflags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,46 @@ where
}
}

impl<T> fmt::Binary for BitFlags<T>
where
T: RawBitFlags,
T::Type: fmt::Binary,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Binary::fmt(&self.bits(), fmt)
}
}

impl<T> fmt::Octal for BitFlags<T>
where
T: RawBitFlags,
T::Type: fmt::Octal,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::Octal::fmt(&self.bits(), fmt)
}
}

impl<T> fmt::LowerHex for BitFlags<T>
where
T: RawBitFlags,
T::Type: fmt::LowerHex,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::LowerHex::fmt(&self.bits(), fmt)
}
}

impl<T> fmt::UpperHex for BitFlags<T>
where
T: RawBitFlags,
T::Type: fmt::UpperHex,
{
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt::UpperHex::fmt(&self.bits(), fmt)
}
}

/// The default value returned is one with all flags unset, i. e. [`empty`][Self::empty].
impl<T> Default for BitFlags<T>
where
Expand Down

0 comments on commit 6c900d3

Please sign in to comment.