Path: blob/main/crates/component-macro/tests/expanded/empty_concurrent.rs
3068 views
/// Auto-generated bindings for a pre-instantiated version of a1/// component which implements the world `empty`.2///3/// This structure is created through [`EmptyPre::new`] which4/// takes a [`InstancePre`](wasmtime::component::InstancePre) that5/// has been created through a [`Linker`](wasmtime::component::Linker).6///7/// For more information see [`Empty`] as well.8pub struct EmptyPre<T: 'static> {9instance_pre: wasmtime::component::InstancePre<T>,10indices: EmptyIndices,11}12impl<T: 'static> Clone for EmptyPre<T> {13fn clone(&self) -> Self {14Self {15instance_pre: self.instance_pre.clone(),16indices: self.indices.clone(),17}18}19}20impl<_T: 'static> EmptyPre<_T> {21/// Creates a new copy of `EmptyPre` bindings which can then22/// be used to instantiate into a particular store.23///24/// This method may fail if the component behind `instance_pre`25/// does not have the required exports.26pub fn new(27instance_pre: wasmtime::component::InstancePre<_T>,28) -> wasmtime::Result<Self> {29let indices = EmptyIndices::new(&instance_pre)?;30Ok(Self { instance_pre, indices })31}32pub fn engine(&self) -> &wasmtime::Engine {33self.instance_pre.engine()34}35pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {36&self.instance_pre37}38/// Instantiates a new instance of [`Empty`] within the39/// `store` provided.40///41/// This function will use `self` as the pre-instantiated42/// instance to perform instantiation. Afterwards the preloaded43/// indices in `self` are used to lookup all exports on the44/// resulting instance.45pub fn instantiate(46&self,47mut store: impl wasmtime::AsContextMut<Data = _T>,48) -> wasmtime::Result<Empty> {49let mut store = store.as_context_mut();50let instance = self.instance_pre.instantiate(&mut store)?;51self.indices.load(&mut store, &instance)52}53}54impl<_T: Send + 'static> EmptyPre<_T> {55/// Same as [`Self::instantiate`], except with `async`.56pub async fn instantiate_async(57&self,58mut store: impl wasmtime::AsContextMut<Data = _T>,59) -> wasmtime::Result<Empty> {60let mut store = store.as_context_mut();61let instance = self.instance_pre.instantiate_async(&mut store).await?;62self.indices.load(&mut store, &instance)63}64}65/// Auto-generated bindings for index of the exports of66/// `empty`.67///68/// This is an implementation detail of [`EmptyPre`] and can69/// be constructed if needed as well.70///71/// For more information see [`Empty`] as well.72#[derive(Clone)]73pub struct EmptyIndices {}74/// Auto-generated bindings for an instance a component which75/// implements the world `empty`.76///77/// This structure can be created through a number of means78/// depending on your requirements and what you have on hand:79///80/// * The most convenient way is to use81/// [`Empty::instantiate`] which only needs a82/// [`Store`], [`Component`], and [`Linker`].83///84/// * Alternatively you can create a [`EmptyPre`] ahead of85/// time with a [`Component`] to front-load string lookups86/// of exports once instead of per-instantiation. This87/// method then uses [`EmptyPre::instantiate`] to88/// create a [`Empty`].89///90/// * If you've instantiated the instance yourself already91/// then you can use [`Empty::new`].92///93/// These methods are all equivalent to one another and move94/// around the tradeoff of what work is performed when.95///96/// [`Store`]: wasmtime::Store97/// [`Component`]: wasmtime::component::Component98/// [`Linker`]: wasmtime::component::Linker99pub struct Empty {}100const _: () = {101impl EmptyIndices {102/// Creates a new copy of `EmptyIndices` bindings which can then103/// be used to instantiate into a particular store.104///105/// This method may fail if the component does not have the106/// required exports.107pub fn new<_T>(108_instance_pre: &wasmtime::component::InstancePre<_T>,109) -> wasmtime::Result<Self> {110let _component = _instance_pre.component();111let _instance_type = _instance_pre.instance_type();112Ok(EmptyIndices {})113}114/// Uses the indices stored in `self` to load an instance115/// of [`Empty`] from the instance provided.116///117/// Note that at this time this method will additionally118/// perform type-checks of all exports.119pub fn load(120&self,121mut store: impl wasmtime::AsContextMut,122instance: &wasmtime::component::Instance,123) -> wasmtime::Result<Empty> {124let _ = &mut store;125let _instance = instance;126Ok(Empty {})127}128}129impl Empty {130/// Convenience wrapper around [`EmptyPre::new`] and131/// [`EmptyPre::instantiate`].132pub fn instantiate<_T>(133store: impl wasmtime::AsContextMut<Data = _T>,134component: &wasmtime::component::Component,135linker: &wasmtime::component::Linker<_T>,136) -> wasmtime::Result<Empty> {137let pre = linker.instantiate_pre(component)?;138EmptyPre::new(pre)?.instantiate(store)139}140/// Convenience wrapper around [`EmptyIndices::new`] and141/// [`EmptyIndices::load`].142pub fn new(143mut store: impl wasmtime::AsContextMut,144instance: &wasmtime::component::Instance,145) -> wasmtime::Result<Empty> {146let indices = EmptyIndices::new(&instance.instance_pre(&store))?;147indices.load(&mut store, instance)148}149/// Convenience wrapper around [`EmptyPre::new`] and150/// [`EmptyPre::instantiate_async`].151pub async fn instantiate_async<_T>(152store: impl wasmtime::AsContextMut<Data = _T>,153component: &wasmtime::component::Component,154linker: &wasmtime::component::Linker<_T>,155) -> wasmtime::Result<Empty>156where157_T: Send,158{159let pre = linker.instantiate_pre(component)?;160EmptyPre::new(pre)?.instantiate_async(store).await161}162}163};164165166