From 43fb922de864e7c76dd00fa632eed96bc5f7a2a4 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 12 Mar 2020 14:49:43 +0100 Subject: [PATCH] feat(interface-types) Implement `Error` on errors. --- src/errors.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/errors.rs b/src/errors.rs index 24ca556..5df5c49 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,6 +3,7 @@ use crate::{ast::InterfaceType, interpreter::Instruction}; use std::{ + error::Error, fmt::{self, Display, Formatter}, result::Result, string::{self, ToString}, @@ -28,6 +29,14 @@ pub struct WasmValueNativeCastError { pub to: InterfaceType, } +impl Error for WasmValueNativeCastError {} + +impl Display for WasmValueNativeCastError { + fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { + write!(formatter, "{:?}", self) + } +} + /// Structure to represent the errors for instructions. #[derive(Debug)] pub struct InstructionError { @@ -47,6 +56,8 @@ impl InstructionError { } } +impl Error for InstructionError {} + impl Display for InstructionError { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { write!( @@ -140,6 +151,8 @@ pub enum InstructionErrorKind { String(string::FromUtf8Error), } +impl Error for InstructionErrorKind {} + impl Display for InstructionErrorKind { fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { match self {