mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-24 18:02:13 +00:00
Update plugin example to use serde and typetag for WASI
This commit is contained in:
parent
e4a51484a7
commit
48509e97bd
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -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",
|
||||
|
@ -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"]
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user