Example of crate compiles within crate, but not standalone

I'm using crate jpeg2k. If I get it from Github and compile it, all the examples compile and run. But if I extract one of the examples, it won't compile as a standalone program. Error is:

error[E0277]: the trait bound `DynamicImage: From<&jpeg2k::Image>` is not satisfied
  --> src/main.rs:51:27
   |
51 |   let img: DynamicImage = (&jp2_image).try_into()?;
   |                           ^^^^^^^^^^^^ -------- required by a bound introduced by this call
   |                           |
   |                           the trait `From<&jpeg2k::Image>` is not implemented for `DynamicImage`
   |
   = help: the following other types implement trait `From<T>`:
             <DynamicImage as From<ImageBuffer<Luma<f32>, Vec<f32>>>>
             <DynamicImage as From<ImageBuffer<Luma<u16>, Vec<u16>>>>
             <DynamicImage as From<ImageBuffer<Luma<u8>, Vec<u8>>>>
             <DynamicImage as From<ImageBuffer<LumaA<f32>, Vec<f32>>>>
             <DynamicImage as From<ImageBuffer<LumaA<u16>, Vec<u16>>>>
             <DynamicImage as From<ImageBuffer<LumaA<u8>, Vec<u8>>>>
             <DynamicImage as From<ImageBuffer<Rgba<f32>, Vec<f32>>>>
             <DynamicImage as From<ImageBuffer<Rgba<u16>, Vec<u16>>>>
           and 4 others
   = note: required for `&jpeg2k::Image` to implement `Into<DynamicImage>`
   = note: required for `DynamicImage` to implement `TryFrom<&jpeg2k::Image>`
   = note: required for `&jpeg2k::Image` to implement `TryInto<DynamicImage>`

The example is jpeg2k/convert_jp2.rs at main · Neopallium/jpeg2k · GitHub and it will compile as part of that project, but not outside it.

The necessary try_into is not being found. There's a try_from implemented in jpeg2k/image.rs at 6f5259e2c91c3308ce40c90e7db02135c23af62b · Neopallium/jpeg2k · GitHub but for some reason it's not being found.

Here's the Cargo.toml file being used:

[package]
name = "jpeg2ktest"
version = "0.1.0"
edition = "2021"

[dependencies]
jpeg2k = {version = "0.6.2", features = ["image"]}
image = "0.24.5"
log = "0.4"
thiserror = "1.0.30"
anyhow = "1.0"
dotenv = "0.15"
env_logger = "0.9"

Note that the "image" feature is on, so the needed try_from should be present.

What am I missing here?

The version of the image crate you're using isn't compatible with the version jpeg2k is using, so you're getting two instances of the crate which aren't compatible compiled in

It works with

image = "0.23.14"

Ah. Thanks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.