1 /// Auto-generated bindings for a pre-instantiated version of a
2 /// component 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`] or by first creating
22 /// a [`EmptyPre`] followed by using
23 /// [`EmptyPre::instantiate`].
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 component 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 fn instantiate(
48             &self,
49             mut store: impl wasmtime::AsContextMut<Data = _T>,
50         ) -> wasmtime::Result<Empty> {
51             let mut store = store.as_context_mut();
52             let _instance = self.instance_pre.instantiate(&mut store)?;
53             Ok(Empty {})
54         }
55         pub fn engine(&self) -> &wasmtime::Engine {
56             self.instance_pre.engine()
57         }
58         pub fn instance_pre(&self) -> &wasmtime::component::InstancePre<_T> {
59             &self.instance_pre
60         }
61     }
62     impl Empty {
63         /// Convenience wrapper around [`EmptyPre::new`] and
64         /// [`EmptyPre::instantiate`].
65         pub fn instantiate<_T>(
66             mut store: impl wasmtime::AsContextMut<Data = _T>,
67             component: &wasmtime::component::Component,
68             linker: &wasmtime::component::Linker<_T>,
69         ) -> wasmtime::Result<Empty> {
70             let pre = linker.instantiate_pre(component)?;
71             EmptyPre::new(pre)?.instantiate(store)
72         }
73     }
74 };
75