Friday 1 November 2019

Package collision




The below conflict means you are using a different version of the library to one of your dependencies:


expected enum `THING`, found a different enum `THING`
  
    = note: expected type `&THING` (enum `THING`)
               found type `&THING` (enum `THING`)
note: Perhaps two different versions of crate `NAME` are being used?


This can be checked with (may need to cargo install cargo-tree)

cargo tree


A quick and dirty fix is for Packages to be overriden in cargo.toml with something like:
patch.crates.io if you are really are patching crates.io otherwise specify the url you are patching

[patch.crates-io]
r2d2 = { git = "https://github.com/PassFort/r2d2", branch = "handle-panics-0.8.6" }
[dependencies]
...
to_patch = { git = "ssh://git@github.com/company/project.git"}

[patch.'ssh://github.com/company/project.git']
to_patch= { git = "ssh://git@github.com/company/project.git", }

/\ Note you can't use to_patch and specify a branch. Fork the repo in github or point to a local build.


Or use replace (requires lib name AND version (assumed to be 0.1.0 here):

[replace]
"to_patch:0.1.0" = { git = "ssh://git@github.com/company/project.git" branch="fix"}

Alternatively if you need 2 version of a crate:



It is apparently possible to import 2 different crate versions
 
Cargo.toml: 
[dependencies]
md5 = "0.6"
other-md5 = { version = "0.8", package = "md-5" }
  
code:
use md5::compute;
use other_md5::Md5;

No comments:

Post a Comment