better error trait design

This commit is contained in:
Pat Hickey
2020-01-23 11:21:04 -08:00
parent 7cc0073a3e
commit cb24fd97c0
5 changed files with 29 additions and 72 deletions

View File

@@ -1,4 +1,4 @@
use crate::{GuestPtr, GuestPtrMut};
use crate::{GuestPtr, GuestPtrMut, MemoryError};
use thiserror::Error;
pub trait GuestType: Sized {
@@ -66,3 +66,10 @@ macro_rules! builtin_copy {
// These definitions correspond to all the witx BuiltinType variants that are Copy:
builtin_copy!(u8, i8, u16, i16, u32, i32, u64, i64, f32, f64, usize, char);
pub trait GuestError {
type Context;
fn is_success(&self) -> bool;
fn from_memory_error(memory_error: MemoryError, ctx: &mut Self::Context) -> Self;
fn from_value_error(value_error: GuestValueError, ctx: &mut Self::Context) -> Self;
}

View File

@@ -3,6 +3,6 @@ mod guest_type;
mod memory;
mod region;
pub use guest_type::{GuestType, GuestTypeClone, GuestTypeCopy, GuestValueError};
pub use guest_type::{GuestError, GuestType, GuestTypeClone, GuestTypeCopy, GuestValueError};
pub use memory::{GuestMemory, GuestPtr, GuestPtrMut, MemoryError};
pub use region::Region;