feat: add __wasm/rust-wasm-plugins-examples/
This commit is contained in:
23
__wasm/rust-wasm-plugins-examples/plugin/Cargo.toml
Normal file
23
__wasm/rust-wasm-plugins-examples/plugin/Cargo.toml
Normal file
@@ -0,0 +1,23 @@
|
||||
[package]
|
||||
edition = "2021"
|
||||
|
||||
name = "plugin"
|
||||
description = "Rust Wasm Plugins Example"
|
||||
version = "0.0.1"
|
||||
rust-version = "1.84"
|
||||
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/tliron/rust-wasm-plugins-example"
|
||||
documentation = "https://github.com/tliron/rust-wasm-plugins-example"
|
||||
authors = ["Tal Liron"]
|
||||
|
||||
readme = "../README.md"
|
||||
|
||||
categories = ["wasm"]
|
||||
keywords = ["wasm", "wasi", "wit", "wasmtime", "examples"]
|
||||
|
||||
[dependencies]
|
||||
wit-bindgen = "0.41.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
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