use crate::epoll::EpollFlags;
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Interest(EpollFlags);
impl Default for Interest {
fn default() -> Self {
Self(EpollFlags::empty())
}
}
impl From<EpollFlags> for Interest {
fn from(value: EpollFlags) -> Self {
Self::new(value)
}
}
impl From<Interest> for EpollFlags {
fn from(value: Interest) -> Self {
value.bitflags()
}
}
impl Interest {
pub const fn new(flags: EpollFlags) -> Self {
Self(flags)
}
pub const fn bitflags(&self) -> EpollFlags {
self.0
}
const fn add(self, flags: EpollFlags) -> Self {
Self(self.0.union(flags))
}
const fn remove(self, flags: EpollFlags) -> Self {
Self(self.0.difference(flags))
}
pub const fn read(self) -> Self {
self.add(EpollFlags::EPOLLIN)
}
pub const fn write(self) -> Self {
self.add(EpollFlags::EPOLLOUT)
}
pub const fn read_write(self) -> Self {
self.read().write()
}
pub const fn read_hangup(self) -> Self {
self.add(EpollFlags::EPOLLRDHUP)
}
pub const fn priority(self) -> Self {
self.add(EpollFlags::EPOLLPRI)
}
pub const fn edge_triggered(self) -> Self {
self.add(EpollFlags::EPOLLET)
}
pub const fn oneshot(self) -> Self {
self.add(EpollFlags::EPOLLONESHOT)
}
#[cfg(not(target_arch = "mips"))]
pub const fn wakeup(self) -> Self {
self.add(EpollFlags::EPOLLWAKEUP)
}
pub const fn exclusive(self) -> Self {
self.add(EpollFlags::EPOLLEXCLUSIVE)
}
pub const fn remove_read(self) -> Self {
self.remove(EpollFlags::EPOLLIN)
}
pub const fn remove_write(self) -> Self {
self.remove(EpollFlags::EPOLLOUT)
}
pub const fn remove_read_hangup(self) -> Self {
self.remove(EpollFlags::EPOLLRDHUP)
}
pub const fn remove_priority(self) -> Self {
self.remove(EpollFlags::EPOLLPRI)
}
pub const fn remove_edge_triggered(self) -> Self {
self.remove(EpollFlags::EPOLLET)
}
pub const fn remove_oneshot(self) -> Self {
self.remove(EpollFlags::EPOLLONESHOT)
}
#[cfg(not(target_arch = "mips"))]
pub const fn remove_wakeup(self) -> Self {
self.remove(EpollFlags::EPOLLWAKEUP)
}
pub const fn remove_exclusive(self) -> Self {
self.remove(EpollFlags::EPOLLEXCLUSIVE)
}
}
pub const fn interest() -> Interest {
Interest::new(EpollFlags::empty())
}