Skip to content

Commit 05919bb

Browse files
committed
Add BitFlags::{EMPTY, ALL}
1 parent 0b33b75 commit 05919bb

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

enumflags_derive/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ fn gen_enumflags(ident: &Ident, item: &DeriveInput, data: &DataEnum)
233233
impl ::enumflags2::_internal::RawBitFlags for #ident {
234234
type Type = #ty;
235235

236+
const EMPTY: Self::Type = 0;
237+
236238
const ALL_BITS: Self::Type =
237239
0 #(| (#repeated_name::#variant_names as #ty))*;
238240

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ pub mod _internal {
167167
/// The underlying integer type.
168168
type Type: BitFlagNum;
169169

170+
/// A value with no bits set.
171+
const EMPTY: Self::Type;
172+
170173
/// A value with all flag bits set.
171174
const ALL_BITS: Self::Type;
172175

@@ -334,6 +337,18 @@ where
334337
unsafe { BitFlags::new(T::ALL_BITS) }
335338
}
336339

340+
/// An empty `BitFlags`. Equivalent to [`empty()`],
341+
/// but works in a const context.
342+
///
343+
/// [`empty()`]: #method.empty
344+
pub const EMPTY: Self = BitFlags { val: T::EMPTY };
345+
346+
/// A `BitFlags` with all flags set. Equivalent to [`all()`],
347+
/// but works in a const context.
348+
///
349+
/// [`all()`]: #method.all
350+
pub const ALL: Self = BitFlags { val: T::ALL_BITS };
351+
337352
/// Returns true if all flags are set
338353
pub fn is_all(self) -> bool {
339354
self.val == T::ALL_BITS

0 commit comments

Comments
 (0)