diff options
author | Chih-hung Hsieh <chh@google.com> | 2020-11-05 23:03:37 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-11-05 23:03:37 +0000 |
commit | 8414138e74aa469015108049230e70b0a325c6e9 (patch) | |
tree | deaa1e4c18a6a0624b02ead4f7fdd5bf985235d1 /src/interest.rs | |
parent | 3c582418efff72b2eb8934627f9ee0281ed79163 (diff) | |
parent | 3a1a50620397b347db105e65b3cab650c2c7bb72 (diff) | |
download | mio-8414138e74aa469015108049230e70b0a325c6e9.tar.gz |
Merge "Upgrade rust/crates/mio to 0.7.5"
Diffstat (limited to 'src/interest.rs')
-rw-r--r-- | src/interest.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/interest.rs b/src/interest.rs index 6bc5929..ee5158a 100644 --- a/src/interest.rs +++ b/src/interest.rs @@ -8,7 +8,7 @@ use std::{fmt, ops}; /// registered with [readable] interests and the socket becomes writable, no /// event will be returned from a call to [`poll`]. /// -/// [registering]: struct.Registry.html#method.reregister +/// [registering]: struct.Registry.html#method.register /// [`event::Source`]: ./event/trait.Source.html /// [`Poll`]: struct.Poll.html /// [readable]: struct.Interest.html#associatedconstant.READABLE @@ -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 |