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