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::p2::{IoView, WasiCtx, 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 IoView for Ctx { 29 fn table(&mut self) -> &mut ResourceTable { 30 &mut self.table 31 } 32 } 33 34 impl WasiView for Ctx { 35 fn ctx(&mut self) -> &mut WasiCtx { 36 &mut self.wasi 37 } 38 } 39 40 impl HasData for Ctx { 41 type Data<'a> = &'a mut Self; 42 } 43