Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ipnetwork mismatched types #160

Closed
matteyeux opened this issue Jul 5, 2022 · 2 comments
Closed

Ipnetwork mismatched types #160

matteyeux opened this issue Jul 5, 2022 · 2 comments

Comments

@matteyeux
Copy link

matteyeux commented Jul 5, 2022

Hi !
Since version 0.20.0 I fail to build my tool because there is a mismatch between IpNetwork types :

λ ~/dev/fail(main*) » cargo run
    Updating crates.io index
   Compiling fail v0.1.0 (/home/mathieu/dev/fail)
error[E0308]: mismatched types
 --> src/main.rs:8:17
  |
7 |             match ip {
  |                   -- this expression has type `ipnetwork::IpNetwork`
8 |                 IpNetwork::V4(ipv4) => {
  |                 ^^^^^^^^^^^^^^^^^^^ expected enum `ipnetwork::IpNetwork`, found enum `IpNetwork`
  |
  = note: perhaps two different versions of crate `ipnetwork` are being used?

error[E0308]: mismatched types
  --> src/main.rs:11:17
   |
7  |             match ip {
   |                   -- this expression has type `ipnetwork::IpNetwork`
...
11 |                 IpNetwork::V6(ipv6) => {
   |                 ^^^^^^^^^^^^^^^^^^^ expected enum `ipnetwork::IpNetwork`, found enum `IpNetwork`
   |
   = note: perhaps two different versions of crate `ipnetwork` are being used?

For more information about this error, try `rustc --explain E0308`.
error: could not compile `fail` due to 2 previous errors

Here is the snippet I try to build bellow :

use ipnetwork::IpNetwork;
use pnet_datalink;

fn main() {
    for iface in pnet_datalink::interfaces() {
        for ip in iface.ips {
            match ip {
                IpNetwork::V4(ipv4) => {
                    println!("ipv4 : {}", ipv4.ip());
                }
                IpNetwork::V6(ipv6) => {
                    println!("ipv6 : {}", ipv6.ip());
                }
            }
        }
    }
}

It also uses pnet_datalink, but I only updated ipnetwork, that's why I suspect the issue to be related to this repo (I'm new to Rust so I may be wrong).

Any idea how I can fix this problem ?

Thanks.

@paolobarbolini
Copy link
Contributor

It also uses pnet_datalink, but I only update ipnetwork, that why I suspect the issue to be related to this repo

The issue is with the fact that you can't have types from a crate's version work with the same types from another version, even if type's structures are exactly equal. Make sure the versions match and it should all go back to working fine.

@matteyeux
Copy link
Author

Oh that perfectly makes sense, I'll stay on 0.19.0 until ipnetwork version is bumped on libpnet.

thank you @paolobarbolini !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants