wasm/
lib.rs

1#![no_std]
2#![deny(
3    clippy::missing_safety_doc,
4    clippy::undocumented_unsafe_blocks,
5    unsafe_op_in_unsafe_fn
6)]
7
8extern crate alloc;
9#[macro_use]
10extern crate log_wrapper;
11
12pub use core::error::ValidationError;
13pub use core::reader::types::{
14    global::GlobalType, ExternType, FuncType, Limits, MemType, NumType, RefType, ResultType,
15    TableType, ValType,
16};
17pub use core::rw_spinlock;
18pub use execution::error::{RuntimeError, TrapError};
19
20pub use execution::store::*;
21pub use execution::value::Value;
22pub use execution::*;
23pub use validation::*;
24
25pub(crate) mod core;
26pub(crate) mod execution;
27pub(crate) mod validation;
28
29/// A definition for a [`Result`] using the optional [`Error`] type.
30pub type Result<T> = ::core::result::Result<T, Error>;
31
32/// An opt-in error type useful for merging all error types of this crate into a single type.
33///
34/// Note: This crate does not use this type in any public interfaces, making it optional for downstream users.
35#[derive(Debug, PartialEq, Eq)]
36pub enum Error {
37    Validation(ValidationError),
38    RuntimeError(RuntimeError),
39}
40
41impl From<ValidationError> for Error {
42    fn from(value: ValidationError) -> Self {
43        Self::Validation(value)
44    }
45}
46
47impl From<RuntimeError> for Error {
48    fn from(value: RuntimeError) -> Self {
49        Self::RuntimeError(value)
50    }
51}
52
53#[cfg(test)]
54mod test {
55    use crate::{Error, RuntimeError, ValidationError};
56
57    #[test]
58    fn error_conversion_validation_error() {
59        let validation_error = ValidationError::InvalidMagic;
60        let error: Error = validation_error.into();
61
62        assert_eq!(error, Error::Validation(ValidationError::InvalidMagic))
63    }
64
65    #[test]
66    fn error_conversion_runtime_error() {
67        let runtime_error = RuntimeError::ModuleNotFound;
68        let error: Error = runtime_error.into();
69
70        assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound))
71    }
72}