Trait ToWasmtimeResult
pub trait ToWasmtimeResult<T> {
// Required method
fn to_wasmtime_result(self) -> Result<T, Error>;
}Expand description
Extension trait for easily converting anyhow::Results into
wasmtime::Results.
This is a small convenience helper to replace
anyhow_result.map_err(wasmtime::Error::from_anyhow) with
anyhow_result.to_wasmtime_result().
Requires that the "anyhow" cargo feature is enabled.
§Example
#![cfg(feature = "anyhow")]
use wasmtime::ToWasmtimeResult as _;
fn returns_anyhow_result() -> anyhow::Result<u32> {
anyhow::bail!("eep")
}
fn returns_wasmtime_result() -> wasmtime::Result<()> {
// The following is equivalent to
//
// returns_anyhow_result()
// .map_err(wasmtime::Error::from_anyhow)?;
returns_anyhow_result().to_wasmtime_result()?;
Ok(())
}
let error: wasmtime::Error = returns_wasmtime_result().unwrap_err();
assert!(error.is::<anyhow::Error>());
assert_eq!(error.to_string(), "eep");Required Methods§
fn to_wasmtime_result(self) -> Result<T, Error>
fn to_wasmtime_result(self) -> Result<T, Error>
Convert this anyhow::Result<T> into a wasmtime::Result<T>.