feat: add __wasm/rust-wasm-plugins-examples/

This commit is contained in:
2025-07-12 13:22:38 +08:00
parent f2fd57c342
commit e45d14498c
19 changed files with 3195 additions and 11 deletions

View File

@@ -0,0 +1,8 @@
// Note that we are using the full notation of the macro in order
// to add some options that allow the bindings to live in this independent file
wit_bindgen::generate!({
path: "../assets/wit/acme-plugins.wit",
default_bindings_module: "crate::bindings",
pub_export_macro: true,
});

View File

@@ -0,0 +1,2 @@
mod bindings;
mod quote_prettify;

View File

@@ -0,0 +1,21 @@
use super::bindings::{acme::plugins::host, export, exports::acme::plugins::prettify_plugin};
// This is our implementation of the "prettify" plugin type
// (=WIT world)
// We shall make the content pretty by quoting all words
// Gorgeous!
pub struct QuotePrettifyPlugin;
export!(QuotePrettifyPlugin);
impl prettify_plugin::Guest for QuotePrettifyPlugin {
fn prettify(content: String) -> String {
host::log("thank you for using the quote prettify plugin!");
let words = content.split(" ");
let words: Vec<String> = words.map(|word| format!("{:?}", word)).collect();
words.join(" ")
}
}