xref: /wasmtime-44.0.1/crates/core/src/error/mod.rs (revision bda02c19)
1 //! Wasmtime's universal error handling types.
2 //!
3 //! 99% API-compatible with `anyhow`, but additionally handles out-of-memory
4 //! errors, instead of aborting the process.
5 //!
6 //! See the [`Error`] documentation for more details.
7 
8 #[cfg(feature = "backtrace")]
9 mod backtrace;
10 mod boxed;
11 mod context;
12 mod error;
13 mod oom;
14 mod ptr;
15 #[cfg(feature = "anyhow")]
16 mod to_wasmtime_result;
17 mod vtable;
18 
19 #[doc(hidden)]
20 pub mod macros;
21 
22 pub use crate::{bail, ensure, format_err};
23 #[cfg(feature = "backtrace")]
24 pub use backtrace::disable_backtrace;
25 pub use context::Context;
26 pub use error::*;
27 pub use oom::OutOfMemory;
28 #[cfg(feature = "anyhow")]
29 pub use to_wasmtime_result::ToWasmtimeResult;
30 
31 /// A result of either `Ok(T)` or an [`Err(Error)`][Error].
32 pub type Result<T, E = Error> = core::result::Result<T, E>;
33 
34 /// Return `core::result::Result::<T, wasmtime::Error>::Ok(value)`.
35 ///
36 /// Useful in situations where Rust's type inference cannot figure out that the
37 /// `Result`'s error type is [`Error`].
38 #[allow(non_snake_case, reason = "matching anyhow API")]
39 pub fn Ok<T>(value: T) -> Result<T> {
40     core::result::Result::Ok(value)
41 }
42