Compilation error because two different versions of crate are being used?

Hi all,

New to Rust programming and this is my first post here. I need help with probably a dependency problem.

My crate depends on libpnet, version "^0.25.0". libpnet uses the ipnetwork crate version "0.15.1". My crate also uses the ipnetwork crate. When I was using the same version as libpnet does, my crate compiles fine. But if I upgrade the version of ipnetwork in my crate's Cargo.toml to the latest "0.16.0", I get the following error which I don't know how to fix (except staying on 0.15.1 in my crate):

error[E0308]: mismatched types
  --> ucat/src/interface.rs:28:5
   |
28 |     iface.ips.iter().find(|ipn| ipn.is_ipv4())
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `ipnetwork::IpNetwork`, found a different enum `ipnetwork::IpNetwork`
   |
   = note: expected enum `std::option::Option<&ipnetwork::IpNetwork>` (enum `ipnetwork::IpNetwork`)
              found enum `std::option::Option<&ipnetwork::IpNetwork>` (enum `ipnetwork::IpNetwork`)
   = note: perhaps two different versions of crate `ipnetwork` are being used?

error: aborting due to previous error

The function that contains this line of code failing to compile:

fn find_ipv4(iface: &NetworkInterface) -> Option<&IpNetwork> {
    iface.ips.iter().find(|ipn| ipn.is_ipv4())
}

The ips field of the pnet::datalink::NetworkInterface struct has the type Vec<IpNetwork>. The Docs link of this struct is here. The Docs link of the IpNetwork enum is here.

Same error with Rust v1.40 (using the rust:1.40 docker image) and Rust v1.41 (on macOS). I have tried cargo clean && cargo build.

In 0.16.0 of ipnetwork, the impl of serde::Deserialize trait has become optional for the enum IpNetwork and its variants, controlled by a feature gate. I have tried compiling with and without the feature. No difference.

Where should I look at for a solution or even a workaround?

Thanks in advance.

If libpnet depends on ipnetwork 0.15, you won't be able to convince it to use 0.16. Perhaps you can find a way of converting into the new version of the type. Or you could submit a PR to libpnet to update their dependencies.

You are probably right about that I shouldn't just upgrade ipnetwork for my crate. Having thought about it, I think ipnetwork 0.16.0 is probably a breaking change due to the now optional impl of the serde trait aforementioned. Thus 0.16.0 and 0.15.1 are indeed imcompatible.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.