better error trait design
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user