component_async_tests/
borrowing_host.rs

1use anyhow::Result;
2use wasmtime::component::Resource;
3
4use super::Ctx;
5
6pub 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`)
18pub struct MyX;
19
20impl bindings::local::local::borrowing_types::HostX for &mut Ctx {
21    fn new(&mut self) -> Result<Resource<MyX>> {
22        Ok(self.table.push(MyX)?)
23    }
24
25    fn foo(&mut self, x: Resource<MyX>) -> Result<()> {
26        _ = self.table.get(&x)?;
27        Ok(())
28    }
29
30    fn drop(&mut self, x: Resource<MyX>) -> Result<()> {
31        self.table.delete(x)?;
32        Ok(())
33    }
34}
35
36impl bindings::local::local::borrowing_types::Host for &mut Ctx {}