Cannot find type `Box2i` in this scope

Hi everyone,

I'm trying to follow the given example at openexr - Rust

use openexr::prelude::*;

fn main() {
    #[cfg(feature = "imath_cgmath")]
    use imath_traits::Box2i;

    let mut file = RgbaInputFile::new("image.exr", 1).unwrap();
    let data_window: Box2i = *file.header().data_window();
    let width = data_window.width() + 1;
    let height = data_window.height() + 1;

but I'm getting this error and I don't know why.

error[E0412]: cannot find type `Box2i` in this scope
 --> src/
8 |     let data_window: Box2i = *file.header().data_window();
  |                      ^^^^^ not found in this scope

my Cargo.toml contains the cgmath dependency and imath_cgmath feature on openexr however to compiler still complains.

cgmath = "0.18.0"
openexr = { version = "0.11.0", features = ["imath_cgmath"] }

Can anyone help me?

The example is probably outdated, there is nothing called Box2i in openexr for version 0.11.0.

But there are here imath-traits 0.4.0 - imath-traits is used by OpenEXR. I think it's supposed to use

#[cfg(feature = "cgmath")]
pub use impl_cgmath::{Box2, Box2d, Box2f, Box2i, Box3, Box3d, Box3f, Box3i};

Am I right?

I think you need to drop the #[cfg(feature... line completely, and then you either need to depend on imath_traits directly or depend on openexr's re-export, if it has one.

Solved @rschoon. Thank you all.