diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-06-30 19:19:45 +0200 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-06-30 19:19:45 +0200 |
| commit | 9c85fa9c3a2066ce851af53d7019e6a25a45af3b (patch) | |
| tree | 79e6608e97f08c0ebdb64125b0c658f5cc4bb33f /examples/wasm-rust.rs | |
| parent | 7e8770cc4e418ef1a8cdfd9b1f59ee14b07cc6c9 (diff) | |
chore: restructure runtime and reduce build dependencies
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'examples/wasm-rust.rs')
| -rw-r--r-- | examples/wasm-rust.rs | 19 |
1 files changed, 17 insertions, 2 deletions
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(()) +} |
