Skip to content

Commit d767919

Browse files
m4dh0rs3meithecatte
authored andcommitted
Add doctest for set
1 parent dc3c613 commit d767919

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/lib.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,25 @@ where
656656
}
657657

658658
/// Inserts if `cond` holds, else removes
659+
///
660+
/// ```
661+
/// # use enumflags2::bitflags;
662+
/// #[derive(Clone, Copy, PartialEq, Debug)]
663+
/// #[bitflags]
664+
/// #[repr(u8)]
665+
/// enum MyFlag {
666+
/// A = 1 << 0,
667+
/// B = 1 << 1,
668+
/// C = 1 << 2,
669+
/// }
670+
///
671+
/// let mut state = MyFlag::A | MyFlag::C;
672+
/// state.set(MyFlag::A | MyFlag::B, 3 > 5);
673+
///
674+
/// // Because the condition was false, both
675+
/// // `A` and `B` are removed from the set
676+
/// assert_eq!(state, MyFlag::C);
677+
/// ```
659678
#[inline(always)]
660679
pub fn set<B: Into<BitFlags<T>>>(&mut self, other: B, cond: bool) {
661680
if cond {

0 commit comments

Comments
 (0)