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