feat: add __wasm/rust-wasm-plugins-examples/
This commit is contained in:
8
__wasm/rust-wasm-plugins-examples/plugin/src/bindings.rs
Normal file
8
__wasm/rust-wasm-plugins-examples/plugin/src/bindings.rs
Normal 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,
|
||||
});
|
||||
2
__wasm/rust-wasm-plugins-examples/plugin/src/lib.rs
Normal file
2
__wasm/rust-wasm-plugins-examples/plugin/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
mod bindings;
|
||||
mod quote_prettify;
|
||||
@@ -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(" ")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user