Line | Count | Source |
1 | | #![no_std] |
2 | | #![deny(clippy::undocumented_unsafe_blocks)] |
3 | | |
4 | | extern crate alloc; |
5 | | #[macro_use] |
6 | | extern crate log_wrapper; |
7 | | |
8 | | pub use core::error::ValidationError; |
9 | | pub use core::reader::types::{ |
10 | | export::ExportDesc, global::GlobalType, Limits, NumType, RefType, ValType, |
11 | | }; |
12 | | pub use core::rw_spinlock; |
13 | | pub use execution::error::{RuntimeError, TrapError}; |
14 | | |
15 | | pub use execution::store::*; |
16 | | pub use execution::value::Value; |
17 | | pub use execution::*; |
18 | | pub use validation::*; |
19 | | |
20 | | pub(crate) mod core; |
21 | | pub(crate) mod execution; |
22 | | pub(crate) mod validation; |
23 | | |
24 | | /// A definition for a [`Result`] using the optional [`Error`] type. |
25 | | pub type Result<T> = ::core::result::Result<T, Error>; |
26 | | |
27 | | /// An opt-in error type useful for merging all error types of this crate into a single type. |
28 | | /// |
29 | | /// Note: This crate does not use this type in any public interfaces, making it optional for downstream users. |
30 | | #[derive(Debug, PartialEq, Eq)] |
31 | | pub enum Error { |
32 | | Validation(ValidationError), |
33 | | RuntimeError(RuntimeError), |
34 | | } |
35 | | |
36 | | impl From<ValidationError> for Error { |
37 | 1 | fn from(value: ValidationError) -> Self { |
38 | 1 | Self::Validation(value) |
39 | 1 | } |
40 | | } |
41 | | |
42 | | impl From<RuntimeError> for Error { |
43 | 1 | fn from(value: RuntimeError) -> Self { |
44 | 1 | Self::RuntimeError(value) |
45 | 1 | } |
46 | | } |
47 | | |
48 | | #[cfg(test)] |
49 | | mod test { |
50 | | use crate::{Error, RuntimeError, ValidationError}; |
51 | | |
52 | | #[test] |
53 | 1 | fn error_conversion_validation_error() { |
54 | 1 | let validation_error = ValidationError::InvalidMagic; |
55 | 1 | let error: Error = validation_error.into(); |
56 | 1 | |
57 | 1 | assert_eq!(error, Error::Validation(ValidationError::InvalidMagic)) |
58 | 1 | } |
59 | | |
60 | | #[test] |
61 | 1 | fn error_conversion_runtime_error() { |
62 | 1 | let runtime_error = RuntimeError::ModuleNotFound; |
63 | 1 | let error: Error = runtime_error.into(); |
64 | 1 | |
65 | 1 | assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound)) |
66 | 1 | } |
67 | | } |