Skip to content

Commit 1270704

Browse files
arcnmxmeithecatte
authored andcommitted
impl std::fmt::{Binary, Octal, {Lower,Upper}Hex} for BitFlags
1 parent 6b0eaae commit 1270704

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
@@ -153,6 +153,46 @@ where
153153
}
154154
}
155155

156+
impl<T> fmt::Binary for BitFlags<T>
157+
where
158+
T: RawBitFlags,
159+
T::Type: fmt::Binary,
160+
{
161+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
162+
fmt::Binary::fmt(&self.bits(), fmt)
163+
}
164+
}
165+
166+
impl<T> fmt::Octal for BitFlags<T>
167+
where
168+
T: RawBitFlags,
169+
T::Type: fmt::Octal,
170+
{
171+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
172+
fmt::Octal::fmt(&self.bits(), fmt)
173+
}
174+
}
175+
176+
impl<T> fmt::LowerHex for BitFlags<T>
177+
where
178+
T: RawBitFlags,
179+
T::Type: fmt::LowerHex,
180+
{
181+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
182+
fmt::LowerHex::fmt(&self.bits(), fmt)
183+
}
184+
}
185+
186+
impl<T> fmt::UpperHex for BitFlags<T>
187+
where
188+
T: RawBitFlags,
189+
T::Type: fmt::UpperHex,
190+
{
191+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
192+
fmt::UpperHex::fmt(&self.bits(), fmt)
193+
}
194+
}
195+
156196
/// The default value returned is one with all flags unset, i. e. [`empty`][Self::empty].
157197
impl<T> Default for BitFlags<T>
158198
where

0 commit comments

Comments
 (0)