Skip to content

Commit

Permalink
Add Interest::remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasdezeeuw committed Oct 23, 2020
1 parent 7358a31 commit b8639c3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/interest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ impl Interest {
Interest(unsafe { NonZeroU8::new_unchecked(self.0.get() | other.0.get()) })
}

/// Removes `other` `Interest` from `self`.
///
/// Returns `None` if the set would be empty after removing `other`.
///
/// ```
/// use mio::Interest;
///
/// const RW_INTERESTS: Interest = Interest::READABLE.add(Interest::WRITABLE);
///
/// // As long a one interest remain this will return `Some`.
/// let w_interest = RW_INTERESTS.remove(Interest::READABLE).unwrap();
/// assert!(!w_interest.is_readable());
/// assert!(w_interest.is_writable());
///
/// // Removing all interests from the set will return `None`.
/// assert_eq!(w_interest.remove(Interest::WRITABLE), None);
///
/// // Its also possible to remove multiple interests at once.
/// assert_eq!(RW_INTERESTS.remove(RW_INTERESTS), None);
/// ```
pub fn remove(self, other: Interest) -> Option<Interest> {
NonZeroU8::new(self.0.get() & !other.0.get()).map(Interest)
}

/// Returns true if the value includes readable readiness.
pub const fn is_readable(self) -> bool {
(self.0.get() & READABLE) != 0
Expand Down

0 comments on commit b8639c3

Please sign in to comment.