use std::fmt;
use std::ops;
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord)]
pub struct PollOpt(usize);
impl PollOpt {
#[inline]
pub fn edge() -> PollOpt {
PollOpt(0x020)
}
#[inline]
pub fn empty() -> PollOpt {
PollOpt(0)
}
#[inline]
pub fn level() -> PollOpt {
PollOpt(0x040)
}
#[inline]
pub fn oneshot() -> PollOpt {
PollOpt(0x080)
}
#[inline]
pub fn urgent() -> PollOpt {
PollOpt(0x100)
}
#[inline]
pub fn all() -> PollOpt {
PollOpt::edge() | PollOpt::level() | PollOpt::oneshot()
}
#[inline]
pub fn is_edge(&self) -> bool {
self.contains(PollOpt::edge())
}
#[inline]
pub fn is_level(&self) -> bool {
self.contains(PollOpt::level())
}
#[inline]
pub fn is_oneshot(&self) -> bool {
self.contains(PollOpt::oneshot())
}
#[inline]
pub fn is_urgent(&self) -> bool {
self.contains(PollOpt::urgent())
}
#[inline]
pub fn bits(&self) -> usize {
self.0
}
#[inline]
pub fn contains(&self, other: PollOpt) -> bool {
(*self & other) == other
}
#[inline]
pub fn insert(&mut self, other: PollOpt) {
self.0 |= other.0;
}
#[inline]
pub fn remove(&mut self, other: PollOpt) {
self.0 &= !other.0;
}
}
impl ops::BitAnd for PollOpt {
type Output = PollOpt;
#[inline]
fn bitand(self, other: PollOpt) -> PollOpt {
PollOpt(self.bits() & other.bits())
}
}
impl ops::BitOr for PollOpt {
type Output = PollOpt;
#[inline]
fn bitor(self, other: PollOpt) -> PollOpt {
PollOpt(self.bits() | other.bits())
}
}
impl ops::Not for PollOpt {
type Output = PollOpt;
#[inline]
fn not(self) -> PollOpt {
PollOpt(!self.bits() & PollOpt::all().bits())
}
}
impl fmt::Debug for PollOpt {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut one = false;
let flags = [(PollOpt::edge(), "Edge-Triggered"),
(PollOpt::level(), "Level-Triggered"),
(PollOpt::oneshot(), "OneShot")];
for &(flag, msg) in &flags {
if self.contains(flag) {
if one {
try!(write!(fmt, " | "))
}
try!(write!(fmt, "{}", msg));
one = true
}
}
Ok(())
}
}