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
And run it using cargo:
cargo run
For an optimized build use:
cargo build --release
cargo run --release
Some ideas on what to do next:
- Heard of WebAssembly? You can actually run this in WebAssembly - see our WASM Training
- Try a full command line parser crate - see blessed.rs for suggestions