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
29pub type Result<T> = ::core::result::Result<T, Error>;
31
32#[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}