Skip to main content


How to install and use the Extism Rust PDK

Create a Rust project

cargo new --lib my-plugin

In the generated Cargo.toml, be sure to include:

crate_type = ["cdylib"]


cargo add extism-pdk

Compiling to WebAssembly

cargo build --release --target wasm32-unknown-unknown

NOTE: --target wasm32-wasi is also fully supported

Latest Docs

Example Usage

Using Config, I/O, & Persisted Variables
use extism_pdk::*;
use serde::Serialize;

const VOWELS: &[char] = &['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'];

struct TestOutput {
pub count: i32,
pub config: String,
pub a: String,

pub fn count_vowels(input: String) -> FnResult<Json<TestOutput>> {
let mut count = 0;
for ch in input.chars() {
if VOWELS.contains(&ch) {
count += 1;

set_var!("a", "this is var a")?;

let a = var::get("a")?.expect("variable 'a' set");
let a = String::from_utf8(a).expect("string from varible value");
let config = config::get("thing").expect("'thing' key set in config");

let output = TestOutput { count, config, a };

When running the above example with extism-cli you will need to pass a configuration value for thing - this can be done using the --config flag:

$ extism-cli code.wasm count_vowels --input "this is a test" --config thing=myValue

Using Extism built-in HTTP
use extism_pdk::*;

// see for docs on this type
pub fn http_get(Json(req): Json<HttpRequest>) -> FnResult<HttpResponse> {
info!("Request to: {}", req.url);
let res = http::request::<()>(&req, None)?;

Host functions

A host function can be imported using an extern function:

use extism_pdk::*;

extern "C" {
fn hello_world(ptr: i64) -> i64;