feat(interface-types) Implement Error on errors.

This commit is contained in:
Ivan Enderlin 2020-03-12 14:49:43 +01:00
parent c41979400e
commit 43fb922de8

View File

@ -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 {