wasmi/tests/derives.rs

37 lines
755 B
Rust
Raw Normal View History

2019-01-25 10:39:59 +00:00
// If you are to update this code, make sure you update the example in `wasmi-derive`.
2019-01-19 00:31:47 +00:00
extern crate wasmi;
2019-01-25 09:43:03 +00:00
extern crate wasmi_derive;
2019-01-19 00:31:47 +00:00
use std::fmt;
2019-01-25 09:43:03 +00:00
use wasmi::HostError;
use wasmi_derive::derive_externals;
2019-01-19 00:31:47 +00:00
#[derive(Debug)]
struct NoInfoError;
impl HostError for NoInfoError {}
impl fmt::Display for NoInfoError {
2019-01-25 09:43:03 +00:00
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "NoInfoError")
}
2019-01-19 00:31:47 +00:00
}
struct NonStaticExternals<'a> {
state: &'a mut usize,
}
#[derive_externals]
impl<'a> NonStaticExternals<'a> {
pub fn hello(&self, a: u32, b: u32) -> u32 {
a + b
}
pub fn increment(&mut self) {
*self.state += 1;
}
pub fn traps(&self) -> Result<(), NoInfoError> {
Err(NoInfoError)
}
}