[−][src]Trait wasmi::HostError
Trait that allows the host to return custom error.
It should be useful for representing custom traps, troubles at instantiation time or other host specific conditions.
Examples
use std::fmt; use wasmi::{Error, HostError}; #[derive(Debug)] struct MyError { code: u32, } impl fmt::Display for MyError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "MyError, code={}", self.code) } } impl HostError for MyError { } fn failable_fn() -> Result<(), Error> { let my_error = MyError { code: 1312 }; Err(Error::Host(Box::new(my_error))) } match failable_fn() { Err(Error::Host(host_error)) => { let my_error = host_error.downcast_ref::<MyError>().unwrap(); assert_eq!(my_error.code, 1312); } _ => panic!(), }
Implementations
impl dyn HostError
[src]
pub fn downcast_ref<T: HostError>(&self) -> Option<&T>
[src]
Attempt to downcast this HostError
to a concrete type by reference.
pub fn downcast_mut<T: HostError>(&mut self) -> Option<&mut T>
[src]
Attempt to downcast this HostError
to a concrete type by mutable
reference.