4 ms·
I don't know if others do this, or if the Rust style guide particularly sanctions it, but in match sections that get overly verbose like that, I find it useful
by deathanatos 7y ago
I don't know if others do this, or if the Rust style guide particularly sanctions it, but in match sections that get overly verbose like that, I find it useful to do a local use statement to pull the enum variants into scope. E.g.,
use image::ColorType::*;
match ... {
RGB(_) => DynamicImage::new_rgb8(w, h),
RGBA(_) => DynamicImage::new_rgb8a(w, h),
}
If you don't necessarily want the variants in the broader scope, it keeps them out of it, but within the local context of the match, the reader often will know what's being referred to. (And if they don't, the use statement will tell them.)
Also, the author already has DynamicImage available in the scope (there's a use for it at the top) so the image:: prefix isn't needed in that section.
There's also what looks like a manual expansion of try!() in run(), that could just be create_diff_image(...)? which would be less verbose.
- leshow 7y agoI prefer the constructors being in the scope personally because it feels similar to Haskell. I'm not sure why they decided to make them hidden.