wasmer_wasix/state/
types.rs1use cfg_if::cfg_if;
3
4cfg_if! {
5 if #[cfg(feature = "host-fs")] {
6 pub use virtual_fs::host_fs::{Stderr, Stdin, Stdout};
7 } else {
8 pub use virtual_fs::mem_fs::{Stderr, Stdin, Stdout};
9 }
10}
11
12#[derive(Debug, Clone)]
13#[allow(clippy::enum_variant_names)]
14pub enum PollEvent {
15 PollIn = 1,
17 PollOut = 2,
20 PollError = 4,
22 PollHangUp = 8,
24 PollInvalid = 16,
26}
27
28impl PollEvent {
29 fn from_i16(raw_num: i16) -> Option<PollEvent> {
30 Some(match raw_num {
31 1 => PollEvent::PollIn,
32 2 => PollEvent::PollOut,
33 4 => PollEvent::PollError,
34 8 => PollEvent::PollHangUp,
35 16 => PollEvent::PollInvalid,
36 _ => return None,
37 })
38 }
39}
40
41#[derive(Debug, Clone)]
42pub struct PollEventBuilder {
43 inner: PollEventSet,
44}
45
46pub type PollEventSet = i16;
47
48#[derive(Debug)]
49pub struct PollEventIter {
50 pes: PollEventSet,
51 i: usize,
52}
53
54impl Iterator for PollEventIter {
55 type Item = PollEvent;
56
57 fn next(&mut self) -> Option<Self::Item> {
58 if self.pes == 0 || self.i > 15 {
59 None
60 } else {
61 while self.i < 16 {
62 let result = PollEvent::from_i16(self.pes & (1 << self.i));
63 self.pes &= !(1 << self.i);
64 self.i += 1;
65 if let Some(r) = result {
66 return Some(r);
67 }
68 }
69 unreachable!("Internal logic error in PollEventIter");
70 }
71 }
72}
73
74pub fn iterate_poll_events(pes: PollEventSet) -> PollEventIter {
75 PollEventIter { pes, i: 0 }
76}
77
78#[allow(dead_code)]
79impl PollEventBuilder {
80 pub fn new() -> PollEventBuilder {
81 PollEventBuilder { inner: 0 }
82 }
83
84 pub fn add(mut self, event: PollEvent) -> PollEventBuilder {
85 self.inner |= event as PollEventSet;
86 self
87 }
88
89 pub fn build(self) -> PollEventSet {
90 self.inner
91 }
92}
93
94#[allow(dead_code)]
95pub trait WasiPath {}
96
97