diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/archive.rs | 2 | ||||
| -rw-r--r-- | examples/linking.rs | 2 | ||||
| -rw-r--r-- | examples/simple.rs | 2 | ||||
| -rw-r--r-- | examples/wasm-rust.rs | 19 |
4 files changed, 20 insertions, 5 deletions
diff --git a/examples/archive.rs b/examples/archive.rs index 4dd714a..ea82c51 100644 --- a/examples/archive.rs +++ b/examples/archive.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::Result; +use eyre::Result; use tinywasm::{parser::Parser, types::TinyWasmModule, Module, Store}; const WASM: &str = r#" diff --git a/examples/linking.rs b/examples/linking.rs index f278266..d215898 100644 --- a/examples/linking.rs +++ b/examples/linking.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::Result; +use eyre::Result; use tinywasm::{Module, Store}; const WASM_ADD: &str = r#" diff --git a/examples/simple.rs b/examples/simple.rs index 6f79c0f..e0842dd 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::Result; +use eyre::Result; use tinywasm::{Module, Store}; const WASM: &str = r#" diff --git a/examples/wasm-rust.rs b/examples/wasm-rust.rs index 921c4a3..79fb8fb 100644 --- a/examples/wasm-rust.rs +++ b/examples/wasm-rust.rs @@ -1,4 +1,4 @@ -use color_eyre::eyre::{eyre, Result}; +use eyre::{eyre, Result}; use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store}; /// Examples of using WebAssembly compiled from Rust with tinywasm. @@ -32,6 +32,7 @@ fn main() -> Result<()> { println!(" printi32"); println!(" fibonacci - calculate fibonacci(30)"); println!(" tinywasm - run printi32 inside of tinywasm inside of itself"); + println!(" argon2id - run argon2id(1000, 2, 1)"); return Ok(()); } @@ -40,6 +41,7 @@ fn main() -> Result<()> { "printi32" => printi32()?, "fibonacci" => fibonacci()?, "tinywasm" => tinywasm()?, + "argon2id" => argon2id()?, "all" => { println!("Running all examples"); println!("\nhello.wasm:"); @@ -50,6 +52,8 @@ fn main() -> Result<()> { fibonacci()?; println!("\ntinywasm.wasm:"); tinywasm()?; + println!("argon2id.wasm:"); + argon2id()?; } _ => {} } @@ -133,10 +137,21 @@ fn fibonacci() -> Result<()> { let mut store = Store::default(); let instance = module.instantiate(&mut store, None)?; - let fibonacci = instance.exported_func::<i32, i32>(&store, "fibonacci")?; + let fibonacci = instance.exported_func::<i32, i32>(&store, "fibonacci_recursive")?; let n = 30; let result = fibonacci.call(&mut store, n)?; println!("fibonacci({}) = {}", n, result); Ok(()) } + +fn argon2id() -> Result<()> { + let module = Module::parse_file("./examples/rust/out/argon2id.wasm")?; + let mut store = Store::default(); + + let instance = module.instantiate(&mut store, None)?; + let argon2id = instance.exported_func::<(i32, i32, i32), i32>(&store, "argon2id")?; + argon2id.call(&mut store, (1000, 2, 1))?; + + Ok(()) +} |
