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::{DecodingError, 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
30pub type Result<T> = ::core::result::Result<T, Error>;
32
33#[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::{core::error::DecodingError, Error, RuntimeError, ValidationError};
57
58 #[test]
59 fn error_conversion_validation_error() {
60 let validation_error = ValidationError::Decoding(DecodingError::InvalidMagic);
61 let error: Error = validation_error.into();
62
63 assert_eq!(
64 error,
65 Error::Validation(ValidationError::Decoding(DecodingError::InvalidMagic))
66 )
67 }
68
69 #[test]
70 fn error_conversion_runtime_error() {
71 let runtime_error = RuntimeError::ModuleNotFound;
72 let error: Error = runtime_error.into();
73
74 assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound))
75 }
76}