I have this function
fn make_image(file_name: &str) {
let mut imgbuf = image::ImageBuffer::new(640, 480);
// for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
// let (r, g, b): (u8, u8, u8);
// r = if x < 320 {
// 128
// } else {
// 192
// };
// g = if y < 240 {
// 128
// } else {
// 192
// };
// b = 155;
// *pixel = image::Rgb([r, g, b]);
// }
}
Note the commented lines.
If I uncomment them, the function would run just fine. I know it does not do anything, but at least it's compilable. However, when it commented the lines as shown, I get the error:
error[E0284]: type annotations needed for `image::ImageBuffer<P, std::vec::Vec<_>>`
--> src\main.rs:5:22
|
5 | let mut imgbuf = image::ImageBuffer::new(640, 480);
| ---------- ^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `P`
| |
| consider giving `imgbuf` the explicit type `image::ImageBuffer<P, std::vec::Vec<_>>`, where the type parameter `P` is specified
|
= note: cannot satisfy `<_ as image::Pixel>::Subpixel == _`
Which is what I am trying to understand, as I am new to Rust.
Why declaring an image buffer without setting its color would result in an error?
Thank you.