1 /// Auto-generated bindings for a pre-instantiated version of a 2 /// copmonent which implements the world `empty`. 3 /// 4 /// This structure is created through [`EmptyPre::new`] which 5 /// takes a [`InstancePre`](wasmtime::component::InstancePre) that 6 /// has been created through a [`Linker`](wasmtime::component::Linker). 7 pub struct EmptyPre<T> { 8 instance_pre: wasmtime::component::InstancePre<T>, 9 } 10 impl<T> Clone for EmptyPre<T> { 11 fn clone(&self) -> Self { 12 Self { 13 instance_pre: self.instance_pre.clone(), 14 } 15 } 16 } 17 /// Auto-generated bindings for an instance a component which 18 /// implements the world `empty`. 19 /// 20 /// This structure is created through either 21 /// [`Empty::instantiate_async`] or by first creating 22 /// a [`EmptyPre`] followed by using 23 /// [`EmptyPre::instantiate_async`]. 24 pub struct Empty {} 25 const _: () = { 26 #[allow(unused_imports)] 27 use wasmtime::component::__internal::anyhow; 28 impl<_T> EmptyPre<_T> { 29 /// Creates a new copy of `EmptyPre` bindings which can then 30 /// be used to instantiate into a particular store. 31 /// 32 /// This method may fail if the compoennt behind `instance_pre` 33 /// does not have the required exports. 34 pub fn new( 35 instance_pre: wasmtime::component::InstancePre<_T>, 36 ) -> wasmtime::Result<Self> { 37 let _component = instance_pre.component(); 38 Ok(EmptyPre { instance_pre }) 39 } 40 /// Instantiates a new instance of [`Empty`] within the 41 /// `store` provided. 42 /// 43 /// This function will use `self` as the pre-instantiated 44 /// instance to perform instantiation. Afterwards the preloaded 45 /// indices in `self` are used to lookup all exports on the 46 /// resulting instance. 47 pub async fn instantiate_async( 48 &self, 49 mut store: impl wasmtime::AsContextMut<Data = _T>, 50 ) -> wasmtime::Result<Empty> 51 where 52 _T: Send, 53 { 54 let mut store = store.as_context_mut(); 55 let _instance = self.instance_pre.instantiate_async(&mut store).await?; 56 Ok(Empty {}) 57 } 58 pub fn engine(&self) -> &wasmtime::Engine { 59 self.instance_pre.engine() 60 } 61 pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> { 62 &self.instance_pre 63 } 64 } 65 impl Empty { 66 /// Convenience wrapper around [`EmptyPre::new`] and 67 /// [`EmptyPre::instantiate_async`]. 68 pub async fn instantiate_async<_T>( 69 mut store: impl wasmtime::AsContextMut<Data = _T>, 70 component: &wasmtime::component::Component, 71 linker: &wasmtime::component::Linker<_T>, 72 ) -> wasmtime::Result<Empty> 73 where 74 _T: Send, 75 { 76 let pre = linker.instantiate_pre(component)?; 77 EmptyPre::new(pre)?.instantiate_async(store).await 78 } 79 } 80 }; 81