1- use color_eyre:: eyre:: Result ;
1+ use color_eyre:: eyre:: { eyre , Result } ;
22use tinywasm:: { Extern , FuncContext , Imports , MemoryStringExt , Module , Store } ;
33
44/// Examples of using WebAssembly compiled from Rust with tinywasm.
@@ -20,6 +20,10 @@ use tinywasm::{Extern, FuncContext, Imports, MemoryStringExt, Module, Store};
2020fn main ( ) -> Result < ( ) > {
2121 pretty_env_logger:: init ( ) ;
2222
23+ if !std:: path:: Path :: new ( "./examples/rust/out/" ) . exists ( ) {
24+ return Err ( eyre ! ( "No WebAssembly files found. See examples/wasm-rust.rs for instructions." ) ) ;
25+ }
26+
2327 let args = std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ;
2428 if args. len ( ) < 2 {
2529 println ! ( "Usage: cargo run --example wasm-rust <rust_example>" ) ;
@@ -54,8 +58,7 @@ fn main() -> Result<()> {
5458}
5559
5660fn tinywasm ( ) -> Result < ( ) > {
57- const TINYWASM : & [ u8 ] = include_bytes ! ( "./rust/out/tinywasm.wasm" ) ;
58- let module = Module :: parse_bytes ( TINYWASM ) ?;
61+ let module = Module :: parse_file ( "./examples/rust/out/tinywasm.wasm" ) ?;
5962 let mut store = Store :: default ( ) ;
6063
6164 let mut imports = Imports :: new ( ) ;
@@ -76,8 +79,7 @@ fn tinywasm() -> Result<()> {
7679}
7780
7881fn hello ( ) -> Result < ( ) > {
79- const HELLO_WASM : & [ u8 ] = include_bytes ! ( "./rust/out/hello.wasm" ) ;
80- let module = Module :: parse_bytes ( HELLO_WASM ) ?;
82+ let module = Module :: parse_file ( "./examples/rust/out/hello.wasm" ) ?;
8183 let mut store = Store :: default ( ) ;
8284
8385 let mut imports = Imports :: new ( ) ;
@@ -106,8 +108,7 @@ fn hello() -> Result<()> {
106108}
107109
108110fn printi32 ( ) -> Result < ( ) > {
109- const HELLO_WASM : & [ u8 ] = include_bytes ! ( "./rust/out/print.wasm" ) ;
110- let module = Module :: parse_bytes ( HELLO_WASM ) ?;
111+ let module = Module :: parse_file ( "./examples/rust/out/print.wasm" ) ?;
111112 let mut store = Store :: default ( ) ;
112113
113114 let mut imports = Imports :: new ( ) ;
@@ -128,8 +129,7 @@ fn printi32() -> Result<()> {
128129}
129130
130131fn fibonacci ( ) -> Result < ( ) > {
131- const FIBONACCI_WASM : & [ u8 ] = include_bytes ! ( "./rust/out/fibonacci.wasm" ) ;
132- let module = Module :: parse_bytes ( FIBONACCI_WASM ) ?;
132+ let module = Module :: parse_file ( "./examples/rust/out/fibonacci.wasm" ) ?;
133133 let mut store = Store :: default ( ) ;
134134
135135 let instance = module. instantiate ( & mut store, None ) ?;
0 commit comments