Line | Count | Source |
1 | | #![doc = include_str!( "../README.md")] |
2 | | #![no_std] |
3 | | |
4 | | extern crate alloc; |
5 | | #[macro_use] |
6 | | extern crate log_wrapper; |
7 | | |
8 | | pub use crate::{ |
9 | | core::{ |
10 | | decoding::{error::DecodingError, modules::custom_section::CustomSection}, |
11 | | rw_spinlock, |
12 | | structure::instructions, |
13 | | structure::types::{ |
14 | | ExternType, FuncType, GlobalType, Limits, MemType, NumType, RefType, ResultType, |
15 | | TableType, ValType, |
16 | | }, |
17 | | }, |
18 | | execution::{ |
19 | | config::Config, |
20 | | error::{RuntimeError, TrapError}, |
21 | | resumable::*, |
22 | | runtime_structure::{ |
23 | | addresses::*, |
24 | | external_values::ExternVal, |
25 | | store::{Hostcode, InstantiationOutcome, Store}, |
26 | | values::{ExternAddr, Ref, Value, ValueTypeMismatchError, F32, F64}, |
27 | | }, |
28 | | }, |
29 | | validation::{decode_and_validate, error::ValidationError, Module}, |
30 | | }; |
31 | | |
32 | | pub(crate) mod core; |
33 | | pub(crate) mod execution; |
34 | | pub(crate) mod validation; |
35 | | |
36 | | /// A definition for a [`Result`] using the optional [`Error`] type. |
37 | | pub type Result<T> = ::core::result::Result<T, Error>; |
38 | | |
39 | | /// An opt-in error type useful for merging all error types of this crate into a single type. |
40 | | /// |
41 | | /// Note: This crate does not use this type in any public interfaces, making it optional for downstream users. |
42 | | #[derive(Debug, PartialEq, Eq)] |
43 | | pub enum Error { |
44 | | Validation(ValidationError), |
45 | | RuntimeError(RuntimeError), |
46 | | } |
47 | | |
48 | | impl From<ValidationError> for Error { |
49 | 1 | fn from(value: ValidationError) -> Self { |
50 | 1 | Self::Validation(value) |
51 | 1 | } |
52 | | } |
53 | | |
54 | | impl From<RuntimeError> for Error { |
55 | 1 | fn from(value: RuntimeError) -> Self { |
56 | 1 | Self::RuntimeError(value) |
57 | 1 | } |
58 | | } |
59 | | |
60 | | #[cfg(test)] |
61 | | mod test { |
62 | | use crate::{core::decoding::error::DecodingError, Error, RuntimeError, ValidationError}; |
63 | | |
64 | | #[test] |
65 | 1 | fn error_conversion_validation_error() { |
66 | 1 | let validation_error = ValidationError::Decoding(DecodingError::InvalidMagic); |
67 | 1 | let error: Error = validation_error.into(); |
68 | | |
69 | 1 | assert_eq!( |
70 | | error, |
71 | | Error::Validation(ValidationError::Decoding(DecodingError::InvalidMagic)) |
72 | | ) |
73 | 1 | } |
74 | | |
75 | | #[test] |
76 | 1 | fn error_conversion_runtime_error() { |
77 | 1 | let runtime_error = RuntimeError::ModuleNotFound; |
78 | 1 | let error: Error = runtime_error.into(); |
79 | | |
80 | 1 | assert_eq!(error, Error::RuntimeError(RuntimeError::ModuleNotFound)) |
81 | 1 | } |
82 | | } |