# [−] [src] Trait wasmi::HostError

    pub trait HostError: 'static + Display + Debug + Send + Sync { }

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!(),
    }

## Methods

### `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.

## Implementors

Loading content...

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)