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