Path: blob/main/crates/misc/component-async-tests/src/borrowing_host.rs
1692 views
use anyhow::Result;1use wasmtime::component::Resource;23use super::Ctx;45pub mod bindings {6wasmtime::component::bindgen!({7path: "wit",8world: "borrowing-host",9imports: { default: trappable },10with: {11"local:local/borrowing-types/x": super::MyX,12}13});14}1516/// Used as the borrowing type (`local:local/borrowing-types/x`)17pub struct MyX;1819impl bindings::local::local::borrowing_types::HostX for &mut Ctx {20fn new(&mut self) -> Result<Resource<MyX>> {21Ok(self.table.push(MyX)?)22}2324fn foo(&mut self, x: Resource<MyX>) -> Result<()> {25_ = self.table.get(&x)?;26Ok(())27}2829fn drop(&mut self, x: Resource<MyX>) -> Result<()> {30self.table.delete(x)?;31Ok(())32}33}3435impl bindings::local::local::borrowing_types::Host for &mut Ctx {}363738