Update plugin example to use serde and typetag for WASI

This commit is contained in:
Mark McCaskey 2019-08-28 14:47:38 -07:00
parent e4a51484a7
commit 48509e97bd
3 changed files with 10 additions and 1 deletions

2
Cargo.lock generated
View File

@ -1498,7 +1498,9 @@ dependencies = [
"errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
"structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"typetag 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.6.0",
"wasmer-dev-utils 0.6.0",

View File

@ -64,6 +64,10 @@ wabt = "0.9.1"
glob = "0.3.0"
rustc_version = "0.2.3"
[dev-dependencies]
serde = { version = "1", features = ["derive"] } # used by the plugin example
typetag = "0.1" # used by the plugin example
[features]
default = ["fast-tests", "wasi", "backend-cranelift"]
"loader-kernel" = ["wasmer-kernel-loader"]

View File

@ -1,3 +1,4 @@
use serde::{Deserialize, Serialize};
use wasmer_runtime::{func, imports, instantiate};
use wasmer_runtime_core::vm::Ctx;
use wasmer_wasi::{
@ -13,7 +14,7 @@ fn it_works(_ctx: &mut Ctx) -> i32 {
5
}
#[derive(Debug)]
#[derive(Debug, Serialize, Deserialize)]
pub struct LoggingWrapper {
pub wasm_module_name: String,
}
@ -86,6 +87,8 @@ impl std::io::Write for LoggingWrapper {
}
// the WasiFile methods aren't relevant for a write-only Stdout-like implementation
// we must use typetag and serde so that our trait objects can be safely Serialized and Deserialized
#[typetag::serde]
impl WasiFile for LoggingWrapper {
fn last_accessed(&self) -> u64 {
0