Final application

You should have this file tree layout:

$ tree
.
├── Cargo.lock
├── Cargo.toml
└── src
    └── main.rs

To recap your final code should look something like this:

use rustagram::{image, RustagramFilter};

fn main() {
    let mut args = std::env::args().skip(1);
    let input = args.next().expect("INPUT required");
    let filter = args.next().expect("FILTER required");
    let output = args.next().unwrap_or_else(|| "output.jpg".to_string());

    let filter_type = filter.parse().expect("can't parse filter name");
    let img = image::open(input).unwrap();
    let out = img.to_rgba8().apply_filter(filter_type);
    out.save(output).unwrap();
}

You can build your code like this:

cargo build --target wasm32-wasi

And run it with wasmtime:

wasmtime --dir . target/wasm32-wasi/debug/rustagram.wasm skyline.jpg 1977

Some ideas on what to do next:

  • Run the application natively: cargo run. Any complications or differences?
  • Inspect the built wasm module using wasm2wat. Can you spot the parts of the code that you've written? Can you find the names of all available filters?
  • Try some other crate you know. Does it work as-is on WebAssembly/with Wasi?