Same as [`Wizer::run`], except for components.
(
&self,
store: &mut Store<T>,
wasm: &[u8],
instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>,
)
| 11 | impl Wizer { |
| 12 | /// Same as [`Wizer::run`], except for components. |
| 13 | pub async fn run_component<T: Send>( |
| 14 | &self, |
| 15 | store: &mut Store<T>, |
| 16 | wasm: &[u8], |
| 17 | instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>, |
| 18 | ) -> wasmtime::Result<Vec<u8>> { |
| 19 | let (cx, instrumented_wasm) = self.instrument_component(wasm)?; |
| 20 | |
| 21 | #[cfg(feature = "wasmprinter")] |
| 22 | log::debug!( |
| 23 | "instrumented wasm: {}", |
| 24 | wasmprinter::print_bytes(&instrumented_wasm).to_wasmtime_result()?, |
| 25 | ); |
| 26 | |
| 27 | let engine = store.engine(); |
| 28 | let component = Component::new(engine, &instrumented_wasm) |
| 29 | .context("failed to compile the Wasm component")?; |
| 30 | let index = self.validate_component_init_func(&component)?; |
| 31 | |
| 32 | let instance = instantiate(store, &component).await?; |
| 33 | self.initialize_component(store, &instance, index).await?; |
| 34 | self.snapshot_component(cx, &mut WasmtimeWizerComponent { store, instance }) |
| 35 | .await |
| 36 | } |
| 37 | |
| 38 | fn validate_component_init_func( |
| 39 | &self, |