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         imports: { default: trappable },
12         with: {
13             "local:local/borrowing-types/x": super::MyX,
14         }
15     });
16 }
17 
18 /// Used as the borrowing type (`local:local/borrowing-types/x`)
19 pub struct MyX;
20 
21 impl bindings::local::local::borrowing_types::HostX for &mut Ctx {
22     fn new(&mut self) -> Result<Resource<MyX>> {
23         Ok(IoView::table(self).push(MyX)?)
24     }
25 
26     fn foo(&mut self, x: Resource<MyX>) -> Result<()> {
27         _ = IoView::table(self).get(&x)?;
28         Ok(())
29     }
30 
31     fn drop(&mut self, x: Resource<MyX>) -> Result<()> {
32         IoView::table(self).delete(x)?;
33         Ok(())
34     }
35 }
36 
37 impl bindings::local::local::borrowing_types::Host for &mut Ctx {}
38