Skip to content

Commit dc3c613

Browse files
m4dh0rs3meithecatte
m4dh0rs3
authored andcommitted
Add set API to BitFlags
1 parent bf161cf commit dc3c613

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/lib.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,20 @@ where
655655
*self &= !other.into();
656656
}
657657

658+
/// Inserts if `cond` holds, else removes
659+
#[inline(always)]
660+
pub fn set<B: Into<BitFlags<T>>>(&mut self, other: B, cond: bool) {
661+
if cond {
662+
self.insert(other);
663+
} else {
664+
self.remove(other);
665+
}
666+
}
667+
658668
/// Returns an iterator that yields each set flag
659669
#[inline]
660670
pub fn iter(self) -> Iter<T> {
661-
Iter {
662-
rest: self,
663-
}
671+
Iter { rest: self }
664672
}
665673
}
666674

0 commit comments

Comments
 (0)