Skip to content

Commit

Permalink
io: add Interest::remove method (#5906)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylonicious committed Sep 10, 2023
1 parent b046c0d commit 65027b6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tokio/src/io/interest.rs
Expand Up @@ -167,6 +167,40 @@ impl Interest {
Self(self.0 | other.0)
}

/// Remove `Interest` from `self`.
///
/// Interests present in `other` but *not* in `self` are ignored.
///
/// Returns `None` if the set would be empty after removing `Interest`.
///
/// # Examples
///
/// ```
/// use tokio::io::Interest;
///
/// const RW_INTEREST: Interest = Interest::READABLE.add(Interest::WRITABLE);
///
/// let w_interest = RW_INTEREST.remove(Interest::READABLE).unwrap();
/// assert!(!w_interest.is_readable());
/// assert!(w_interest.is_writable());
///
/// // Removing all interests from the set returns `None`.
/// assert_eq!(w_interest.remove(Interest::WRITABLE), None);
///
/// // Remove all interests at once.
/// assert_eq!(RW_INTEREST.remove(RW_INTEREST), None);
/// ```
#[must_use = "this returns the result of the operation, without modifying the original"]
pub fn remove(self, other: Interest) -> Option<Interest> {
let value = self.0 & !other.0;

if value != 0 {
Some(Self(value))
} else {
None
}
}

// This function must be crate-private to avoid exposing a `mio` dependency.
pub(crate) fn to_mio(self) -> mio::Interest {
fn mio_add(wrapped: &mut Option<mio::Interest>, add: mio::Interest) {
Expand Down

0 comments on commit 65027b6

Please sign in to comment.