Skip to content

Commit b8639c3

Browse files
committed
Add Interest::remove
1 parent 7358a31 commit b8639c3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/interest.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ impl Interest {
7070
Interest(unsafe { NonZeroU8::new_unchecked(self.0.get() | other.0.get()) })
7171
}
7272

73+
/// Removes `other` `Interest` from `self`.
74+
///
75+
/// Returns `None` if the set would be empty after removing `other`.
76+
///
77+
/// ```
78+
/// use mio::Interest;
79+
///
80+
/// const RW_INTERESTS: Interest = Interest::READABLE.add(Interest::WRITABLE);
81+
///
82+
/// // As long a one interest remain this will return `Some`.
83+
/// let w_interest = RW_INTERESTS.remove(Interest::READABLE).unwrap();
84+
/// assert!(!w_interest.is_readable());
85+
/// assert!(w_interest.is_writable());
86+
///
87+
/// // Removing all interests from the set will return `None`.
88+
/// assert_eq!(w_interest.remove(Interest::WRITABLE), None);
89+
///
90+
/// // Its also possible to remove multiple interests at once.
91+
/// assert_eq!(RW_INTERESTS.remove(RW_INTERESTS), None);
92+
/// ```
93+
pub fn remove(self, other: Interest) -> Option<Interest> {
94+
NonZeroU8::new(self.0.get() & !other.0.get()).map(Interest)
95+
}
96+
7397
/// Returns true if the value includes readable readiness.
7498
pub const fn is_readable(self) -> bool {
7599
(self.0.get() & READABLE) != 0

0 commit comments

Comments
 (0)