#![cfg_attr(not(feature = "net"), allow(unreachable_pub))]
use crate::io::driver::Ready;
use std::fmt;
use std::ops;
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[derive(Clone, Copy, Eq, PartialEq)]
pub struct Interest(mio::Interest);
impl Interest {
pub const READABLE: Interest = Interest(mio::Interest::READABLE);
pub const WRITABLE: Interest = Interest(mio::Interest::WRITABLE);
pub const fn is_readable(self) -> bool {
self.0.is_readable()
}
pub const fn is_writable(self) -> bool {
self.0.is_writable()
}
pub const fn add(self, other: Interest) -> Interest {
Interest(self.0.add(other.0))
}
pub(crate) const fn to_mio(self) -> mio::Interest {
self.0
}
pub(super) fn mask(self) -> Ready {
match self {
Interest::READABLE => Ready::READABLE | Ready::READ_CLOSED,
Interest::WRITABLE => Ready::WRITABLE | Ready::WRITE_CLOSED,
_ => Ready::EMPTY,
}
}
}
impl ops::BitOr for Interest {
type Output = Self;
#[inline]
fn bitor(self, other: Self) -> Self {
self.add(other)
}
}
impl ops::BitOrAssign for Interest {
#[inline]
fn bitor_assign(&mut self, other: Self) {
self.0 = (*self | other).0;
}
}
impl fmt::Debug for Interest {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0.fmt(fmt)
}
}