Skip to content

Commit

Permalink
Add set API to BitFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
m4dh0rs3 authored and meithecatte committed Sep 9, 2023
1 parent bf161cf commit dc3c613
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,20 @@ where
*self &= !other.into();
}

/// Inserts if `cond` holds, else removes
#[inline(always)]
pub fn set<B: Into<BitFlags<T>>>(&mut self, other: B, cond: bool) {
if cond {
self.insert(other);
} else {
self.remove(other);
}
}

/// Returns an iterator that yields each set flag
#[inline]
pub fn iter(self) -> Iter<T> {
Iter {
rest: self,
}
Iter { rest: self }
}
}

Expand Down

0 comments on commit dc3c613

Please sign in to comment.