1 mod bindings { 2 wit_bindgen::generate!({ 3 path: "../misc/component-async-tests/wit", 4 world: "borrowing-callee", 5 }); 6 7 use super::Component; 8 export!(Component); 9 } 10 11 use bindings::{ 12 exports::local::local::{borrowing::Guest as Borrowing, run_bool::Guest as RunBool}, 13 local::local::borrowing_types::X, 14 }; 15 16 struct Component; 17 18 impl Borrowing for Component { foo(x: &X, misbehave: bool)19 async fn foo(x: &X, misbehave: bool) { 20 let handle = x.handle(); 21 wit_bindgen::spawn(async move { 22 if misbehave { 23 unsafe { X::from_handle(handle) }.foo(); 24 } 25 }); 26 x.foo(); 27 } 28 } 29 30 impl RunBool for Component { run(misbehave: bool)31 async fn run(misbehave: bool) { 32 Self::foo(&X::new(), misbehave).await 33 } 34 } 35 36 // Unused function; required since this file is built as a `bin`: main()37fn main() {} 38