1#![no_std]
2#![deny(clippy::undocumented_unsafe_blocks)]
3
4extern crate alloc;
5#[macro_use]
6extern crate log_wrapper;
7
8pub use core::error::ValidationError;
9pub use core::reader::types::{
10 export::ExportDesc, global::GlobalType, Limits, NumType, RefType, ValType,
11};
12pub use core::rw_spinlock;
13pub use execution::error::{RuntimeError, TrapError};
14
15pub use execution::store::*;
16pub use execution::value::Value;
17pub use execution::*;
18pub use validation::*;
19
20pub(crate) mod core;
21pub(crate) mod execution;
22pub(crate) mod validation;
23
24pub type Result<T> = ::core::result::Result<T, Error>;
26
27#[derive(Debug, PartialEq, Eq)]
31pub enum Error {
32 Validation(ValidationError),
33 RuntimeError(RuntimeError),
34}
35
36impl From<ValidationError> for Error {
37 fn from(value: ValidationError) -> Self {
38 Self::Validation(value)
39 }
40}
41
42impl From<RuntimeError> for Error {
43 fn from(value: RuntimeError) -> Self {
44 Self::RuntimeError(value)
45 }
46}
47
48#[cfg(test)]
49mod test {
50 use crate::{Error, RuntimeError, ValidationError};
51
52 #[test]
53 fn error_conversion_validation_error() {
54 let validation_error = ValidationError::InvalidMagic;
55 let error: Error = validation_error.into();
56
57 assert_eq!(error, Error::Validation(ValidationError::InvalidMagic))
58 }
59
60 #[test]
61 fn error_conversion_runtime_error() {
62 let runtime_error = RuntimeError::ModuleNotFound;
63 let error: Error = runtime_error.into();
64
65 assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound))
66 }
67}