generate a module trait and call it

This commit is contained in:
Pat Hickey
2020-01-23 12:46:57 -08:00
parent cb24fd97c0
commit b4f21752b0
7 changed files with 139 additions and 17 deletions

View File

@@ -7,17 +7,21 @@ pub mod test {
value_errors: Vec<::memory::GuestValueError>,
}
impl foo::Foo for WasiCtx {
fn bar(&mut self, an_int: u32, an_float: f32) -> Result<(), types::Errno> {
println!("BAR: {} {}", an_int, an_float);
Ok(())
}
}
// Errno is used as a first return value in the functions above, therefore
// it must implement GuestError with type Context = WasiCtx.
// The context type should let you do logging or debugging or whatever you need
// with these errors. We just push them to vecs.
impl ::memory::GuestError for types::Errno {
type Context = WasiCtx;
fn is_success(&self) -> bool {
match self {
types::Errno::Ok => true,
_ => false,
}
fn success() -> types::Errno {
types::Errno::Ok
}
fn from_memory_error(e: ::memory::MemoryError, ctx: &mut WasiCtx) -> types::Errno {
ctx.mem_errors.push(e);