I would slightly change this code:
use std::error::Error;
fn main() -> Result<(), Box<Error>> {
// Args arrangement
let mut args = std::env::args().skip(1);
assert_eq!(args.len(), 3, "Arguments must be: file_location width height");
// Reading args
let file_location = args.next().unwrap();
let width = args.next().unwrap().parse()?;
let height = args.next().unwrap().parse()?;
// Do the job
let img = image::open(&file_location)?;
img.thumbnail(width, height);
// All was ok
Ok(())
}
You can take advantage of the try operator
?to make the error handling easier.Similarly, you can add a bit of error handling with the
assert_eqline. You can use thelenmethod because this iterator knows exactly how much elements it has.You can use
skipto discard the first element of theArgsiterator.