Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/misc/component-async-tests/src/borrowing_host.rs
1692 views
1
use anyhow::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 {
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
36
impl bindings::local::local::borrowing_types::Host for &mut Ctx {}
37
38