feat: add __network/html-crawl-parse, __wasm/wasmtime-serde-demo
This commit is contained in:
1102
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.lock
generated
Normal file
1102
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.toml
Normal file
14
__wasm/wasmtime-serde-demo/docs/examples/host/Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "Unlicense OR MIT"
|
||||
|
||||
[dependencies]
|
||||
wasmtime_serde_host = {path = "../../../crates/host"}
|
||||
serde = {version = "1.0.159", features = ["derive"]}
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
strip = true
|
||||
29
__wasm/wasmtime-serde-demo/docs/examples/host/src/main.rs
Normal file
29
__wasm/wasmtime-serde-demo/docs/examples/host/src/main.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use wasmtime_serde_host::*;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
struct Human {
|
||||
name: String,
|
||||
age: u8,
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
fn get_human() -> Human {
|
||||
Human {
|
||||
name: "Ferros".to_string(),
|
||||
age: 192,
|
||||
}
|
||||
}
|
||||
|
||||
#[export_fn]
|
||||
fn println(msg: String) {
|
||||
println!("{msg}")
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let host_fns = host_funcs![println, get_human];
|
||||
let runtime = Runtime::from_file("../guest/target/wasm32-unknown-unknown/debug/guest.wasm", host_fns).unwrap();
|
||||
let add_fn = runtime.get_func::<(i32, i32), i32>("add").unwrap();
|
||||
let result = add_fn.call(&(1, 2));
|
||||
println!("{result}");
|
||||
}
|
||||
Reference in New Issue
Block a user