Skip to content

Commit e4af8ac

Browse files
committed
impl std::fmt::{Binary, Octal, {Lower,Upper}Hex} for BitFlags
1 parent 54cc70a commit e4af8ac

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

enumflags/src/lib.rs

+40
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,46 @@ where
169169
}
170170
}
171171

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

0 commit comments

Comments
 (0)