use cfg_if::cfg_if;
#[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize};
cfg_if! {
if #[cfg(feature = "host-fs")] {
pub use virtual_fs::host_fs::{Stderr, Stdin, Stdout};
} else {
pub use virtual_fs::mem_fs::{Stderr, Stdin, Stdout};
}
}
#[derive(Debug, Clone)]
#[allow(clippy::enum_variant_names)]
pub enum PollEvent {
PollIn = 1,
PollOut = 2,
PollError = 4,
PollHangUp = 8,
PollInvalid = 16,
}
impl PollEvent {
fn from_i16(raw_num: i16) -> Option<PollEvent> {
Some(match raw_num {
1 => PollEvent::PollIn,
2 => PollEvent::PollOut,
4 => PollEvent::PollError,
8 => PollEvent::PollHangUp,
16 => PollEvent::PollInvalid,
_ => return None,
})
}
}
#[derive(Debug, Clone)]
pub struct PollEventBuilder {
inner: PollEventSet,
}
pub type PollEventSet = i16;
#[derive(Debug)]
pub struct PollEventIter {
pes: PollEventSet,
i: usize,
}
impl Iterator for PollEventIter {
type Item = PollEvent;
fn next(&mut self) -> Option<Self::Item> {
if self.pes == 0 || self.i > 15 {
None
} else {
while self.i < 16 {
let result = PollEvent::from_i16(self.pes & (1 << self.i));
self.pes &= !(1 << self.i);
self.i += 1;
if let Some(r) = result {
return Some(r);
}
}
unreachable!("Internal logic error in PollEventIter");
}
}
}
pub fn iterate_poll_events(pes: PollEventSet) -> PollEventIter {
PollEventIter { pes, i: 0 }
}
#[allow(dead_code)]
impl PollEventBuilder {
pub fn new() -> PollEventBuilder {
PollEventBuilder { inner: 0 }
}
pub fn add(mut self, event: PollEvent) -> PollEventBuilder {
self.inner |= event as PollEventSet;
self
}
pub fn build(self) -> PollEventSet {
self.inner
}
}
#[allow(dead_code)]
pub trait WasiPath {}