xref: /wasmtime-44.0.1/crates/core/src/error/mod.rs (revision 4a168844)
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 mod to_wasmtime_result;
16 mod vtable;
17 
18 #[doc(hidden)]
19 pub mod macros;
20 
21 pub use crate::{bail, ensure, format_err};
22 #[cfg(feature = "backtrace")]
23 pub use backtrace::disable_backtrace;
24 pub use context::Context;
25 pub use error::*;
26 pub use oom::OutOfMemory;
27 pub use to_wasmtime_result::ToWasmtimeResult;
28 
29 /// A result of either `Ok(T)` or an [`Err(Error)`][Error].
30 pub type Result<T, E = Error> = core::result::Result<T, E>;
31 
32 /// Return `core::result::Result::<T, wasmtime::Error>::Ok(value)`.
33 ///
34 /// Useful in situations where Rust's type inference cannot figure out that the
35 /// `Result`'s error type is [`Error`].
36 #[allow(non_snake_case, reason = "matching anyhow API")]
Ok<T>(value: T) -> Result<T>37 pub fn Ok<T>(value: T) -> Result<T> {
38     core::result::Result::Ok(value)
39 }
40