1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crateResult;
/// Extension trait for easily converting `anyhow::Result`s into
/// `wasmtime::Result`s.
///
/// 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
///
/// ```
/// # fn _foo() {
/// #![cfg(feature = "anyhow")]
/// # use wasmtime_internal_core::error as wasmtime;
/// 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");
/// # }
/// ```