1 use anyhow::Result; 2 use wasmtime::component::Resource; 3 use wasmtime_wasi::p2::IoView; 4 5 use super::Ctx; 6 7 pub mod bindings { 8 wasmtime::component::bindgen!({ 9 path: "wit", 10 world: "borrowing-host", 11 trappable_imports: true, 12 concurrent_imports: true, 13 concurrent_exports: true, 14 async: { 15 only_imports: [] 16 }, 17 with: { 18 "local:local/borrowing-types/x": super::MyX, 19 } 20 }); 21 } 22 23 /// Used as the borrowing type (`local:local/borrowing-types/x`) 24 pub struct MyX; 25 26 impl bindings::local::local::borrowing_types::HostX for &mut Ctx { 27 fn new(&mut self) -> Result<Resource<MyX>> { 28 Ok(IoView::table(self).push(MyX)?) 29 } 30 31 fn foo(&mut self, x: Resource<MyX>) -> Result<()> { 32 _ = IoView::table(self).get(&x)?; 33 Ok(()) 34 } 35 36 fn drop(&mut self, x: Resource<MyX>) -> Result<()> { 37 IoView::table(self).delete(x)?; 38 Ok(()) 39 } 40 } 41 42 impl bindings::local::local::borrowing_types::Host for &mut Ctx {} 43