/// Interest used in registering. /// /// Interest are used in [registering] [`event::Source`]s with [`Poll`], they /// indicate what readiness should be monitored for. For example if a socket is /// registered with [readable] interests and the socket becomes writable, no /// event will be returned from a call to [`poll`]. /// /// [registering]: struct.Registry.html#method.register /// [`event::Source`]: ./event/trait.Source.html /// [`Poll`]: struct.Poll.html /// [readable]: struct.Interest.html#associatedconstant.READABLE /// [`poll`]: struct.Poll.html#method.poll #[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord)] pubstruct Interest(NonZeroU8);
// These must be unique. const READABLE: u8 = 0b0001; const WRITABLE: u8 = 0b0010; // The following are not available on all platforms. const AIO: u8 = 0b0100; const LIO: u8 = 0b1000; const PRIORITY: u8 = 0b10000;
impl Interest { /// Returns a `Interest` set representing readable interests. pubconst READABLE: Interest = Interest(unsafe { NonZeroU8::new_unchecked(READABLE) });
/// Returns a `Interest` set representing writable interests. pubconst WRITABLE: Interest = Interest(unsafe { NonZeroU8::new_unchecked(WRITABLE) });
/// Add together two `Interest`. /// /// This does the same thing as the `BitOr` implementation, but is a /// constant function. /// /// ``` /// use mio::Interest; /// /// const INTERESTS: Interest = Interest::READABLE.add(Interest::WRITABLE); /// # fn silent_dead_code_warning(_: Interest) { } /// # silent_dead_code_warning(INTERESTS) /// ``` #[allow(clippy::should_implement_trait)] #[must_use = "this returns the result of the operation, without modifying the original"] pubconstfn add(self, other: Interest) -> 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); /// ``` #[must_use = "this returns the result of the operation, without modifying the original"] pubfn remove(self, other: Interest) -> Option<Interest> {
NonZeroU8::new(self.0.get() & !other.0.get()).map(Interest)
}
/// Returns true if the value includes readable readiness. #[must_use] pubconstfn is_readable(self) -> bool {
(self.0.get() & READABLE) != 0
}
/// Returns true if the value includes writable readiness. #[must_use] pubconstfn is_writable(self) -> bool {
(self.0.get() & WRITABLE) != 0
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.