Variable does not change

Asked by At

I'm new to rust and still struggle with some concepts. I try to load an image and resize it depending on a boolean value:

fn load_img(img_path: &std::path::PathBuf, resize: bool) -> image::RgbImage {
    let mut img = image::open(img_path).unwrap();
    if resize {
        img = img.resize_exact(200, 200, image::FilterType::Gaussian);
    }
    let img = img.to_rgb();
    let dim = img.dimensions();
    println!("Loaded image \"{}\": {}x{}", img_path.display(), dim.0, dim.1);
    img
}

img.resize_exact(...) returns the same type it was used on, the function is from the crate image.

I expect img to be the resized image after the if block. Yet the size afterwards is not 200x200, thus img contains the same value before and after the if block.

What am I doing wrong?

0 Answers