Add impl From<TrapKind> for Trap
This commit is contained in:
parent
9b5282f2f9
commit
a415932b9d
|
@ -141,7 +141,7 @@ impl FuncInstance {
|
|||
args: &[RuntimeValue],
|
||||
externals: &mut E,
|
||||
) -> Result<Option<RuntimeValue>, Trap> {
|
||||
check_function_args(func.signature(), &args).map_err(|_| Trap::new(TrapKind::UnexpectedSignature))?;
|
||||
check_function_args(func.signature(), &args).map_err(|_| TrapKind::UnexpectedSignature)?;
|
||||
match *func.as_internal() {
|
||||
FuncInstanceInternal::Internal { .. } => {
|
||||
let mut interpreter = Interpreter::new(externals);
|
||||
|
|
|
@ -19,7 +19,7 @@ impl<'a> RuntimeArgs<'a> {
|
|||
///
|
||||
/// Returns `Err` if cast is invalid or not enough arguments.
|
||||
pub fn nth_checked<T>(&self, idx: usize) -> Result<T, Trap> where RuntimeValue: TryInto<T, ::value::Error> {
|
||||
Ok(self.nth_value_checked(idx)?.try_into().map_err(|_| Trap::new(TrapKind::UnexpectedSignature))?)
|
||||
Ok(self.nth_value_checked(idx)?.try_into().map_err(|_| TrapKind::UnexpectedSignature)?)
|
||||
}
|
||||
|
||||
/// Extract argument as a [`RuntimeValue`] by index `idx`.
|
||||
|
|
|
@ -316,6 +316,12 @@ impl From<Trap> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<TrapKind> for Trap {
|
||||
fn from(e: TrapKind) -> Trap {
|
||||
Trap::new(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<validation::Error> for Error {
|
||||
fn from(e: validation::Error) -> Error {
|
||||
Error::Validation(e.to_string())
|
||||
|
|
|
@ -652,7 +652,7 @@ fn dynamically_add_host_func() {
|
|||
host_func_index as usize,
|
||||
);
|
||||
self.table.set(table_index, Some(added_func))
|
||||
.map_err(|_| Trap::new(TrapKind::TableAccessOutOfBounds))?;
|
||||
.map_err(|_| TrapKind::TableAccessOutOfBounds)?;
|
||||
|
||||
Ok(Some(RuntimeValue::I32(table_index as i32)))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue