1 #![expect(clippy::allow_attributes_without_reason)]
2 
3 use std::sync::{Arc, Mutex};
4 use std::task::Waker;
5 
6 use wasmtime::component::{HasData, ResourceTable};
7 use wasmtime_wasi::{WasiCtx, WasiCtxView, WasiView};
8 
9 pub mod borrowing_host;
10 pub mod closed_streams;
11 pub mod resource_stream;
12 pub mod round_trip;
13 pub mod round_trip_direct;
14 pub mod round_trip_many;
15 pub mod sleep;
16 pub mod transmit;
17 pub mod util;
18 pub mod yield_host;
19 
20 /// Host implementation, usable primarily by tests
21 pub struct Ctx {
22     pub wasi: WasiCtx,
23     pub table: ResourceTable,
24     pub wakers: Arc<Mutex<Option<Vec<Waker>>>>,
25     pub continue_: bool,
26 }
27 
28 impl WasiView for Ctx {
29     fn ctx(&mut self) -> WasiCtxView<'_> {
30         WasiCtxView {
31             ctx: &mut self.wasi,
32             table: &mut self.table,
33         }
34     }
35 }
36 
37 impl HasData for Ctx {
38     type Data<'a> = &'a mut Self;
39 }
40