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