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::custom_section::CustomSection;
25pub use validation::*;
26
27pub(crate) mod core;
28pub(crate) mod execution;
29pub(crate) mod validation;
30
31pub type Result<T> = ::core::result::Result<T, Error>;
33
34#[derive(Debug, PartialEq, Eq)]
38pub enum Error {
39 Validation(ValidationError),
40 RuntimeError(RuntimeError),
41}
42
43impl From<ValidationError> for Error {
44 fn from(value: ValidationError) -> Self {
45 Self::Validation(value)
46 }
47}
48
49impl From<RuntimeError> for Error {
50 fn from(value: RuntimeError) -> Self {
51 Self::RuntimeError(value)
52 }
53}
54
55#[cfg(test)]
56mod test {
57 use crate::{core::error::DecodingError, Error, RuntimeError, ValidationError};
58
59 #[test]
60 fn error_conversion_validation_error() {
61 let validation_error = ValidationError::Decoding(DecodingError::InvalidMagic);
62 let error: Error = validation_error.into();
63
64 assert_eq!(
65 error,
66 Error::Validation(ValidationError::Decoding(DecodingError::InvalidMagic))
67 )
68 }
69
70 #[test]
71 fn error_conversion_runtime_error() {
72 let runtime_error = RuntimeError::ModuleNotFound;
73 let error: Error = runtime_error.into();
74
75 assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound))
76 }
77}