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