The structx crate's build.rs will generate bindings.rs composed of some struct definitions which will #[derive( lens_rs::Lens )].
If tested lens-rs_test with cargo test test_structx --all-features, the bindings.rs will be generated as expected( containing #[derive( lens_rs::Lens )] ), but deriving of lens_rs::Lens will not happen.
All will be fine if change the dependency of lens-rs in lens-rs_test's Cargo.toml:
The different compilations is not caused by the difference of lens-rs in github an in crates.io. I have downloaded lens-rs.0.3.1 from crates.io and replaced the local repository's lens-rs directory. The same result: path failed and version passed.
While your project uses lens-rs via a path dependency, structx still uses it via crates.io. So your project includes two different libraries named lens-rs. The structx bindings implement traits from one of these libraries, while your code uses traits from the other.
To fix this, you can use a patch override to make structx use your local copy of lens-rs. Add the following to the Cargo.toml file at the top level of your workspace:
[patch.crates-io]
lens-rs = { path = "lens-rs" }
[Note: This type of question might be more appropriate for the users forum.]
Thanks for your explanations! I didn't notice that two lens-rs existed.
However, I think it is not worth patching structx to use the local copy of lens-rs just for lens-rs_test working with local copy of lens-rs. According to the cargo book:
It is convenient not to change Cargo.toml for switching development/publishing. Patching structx's workspace brings this inconvenience back again. Unfortunately, structx and lens-rs belongs to different repos/workspaces.
You don't need to make any changes to any structx files. Inserting a [patch] section in the lens-rs workspace's Cargo.toml will affect everything that uses lens-rswhen you run Cargo commands within that workspace.
You don't need to make any changes for development versus publication, since the [patch] section there is used only when building within that repo. It won't affect users of the published crates.
To scan for this, you could install cargo-tree with cargo install cargo-tree. When used in a directory that is a rust crate, it will display all dependencies, both direct and transitive, as a tree rooted in the current crate.