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