Skip to content

Commit 045e261

Browse files
committed
impl std::fmt::{Binary, Octal, {Lower,Upper}Hex} for BitFlags
1 parent d91b98f commit 045e261

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

enumflags/src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,46 @@ where
168168
}
169169
}
170170

171+
impl<T> fmt::Binary for BitFlags<T>
172+
where
173+
T: RawBitFlags,
174+
T::Type: fmt::Binary,
175+
{
176+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
177+
fmt::Binary::fmt(&self.bits(), fmt)
178+
}
179+
}
180+
181+
impl<T> fmt::Octal for BitFlags<T>
182+
where
183+
T: RawBitFlags,
184+
T::Type: fmt::Octal,
185+
{
186+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
187+
fmt::Octal::fmt(&self.bits(), fmt)
188+
}
189+
}
190+
191+
impl<T> fmt::LowerHex for BitFlags<T>
192+
where
193+
T: RawBitFlags,
194+
T::Type: fmt::LowerHex,
195+
{
196+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
197+
fmt::LowerHex::fmt(&self.bits(), fmt)
198+
}
199+
}
200+
201+
impl<T> fmt::UpperHex for BitFlags<T>
202+
where
203+
T: RawBitFlags,
204+
T::Type: fmt::UpperHex,
205+
{
206+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
207+
fmt::UpperHex::fmt(&self.bits(), fmt)
208+
}
209+
}
210+
171211
/// The default value returned is one with all flags unset, i. e. [`empty`][Self::empty].
172212
impl<T> Default for BitFlags<T>
173213
where

0 commit comments

Comments
 (0)