by mshroyer · 7y ago · 0 comments
Are there any circumstances in which this approach can have undesirable behavior, for example if the dependency has to deal with some global state?
This seems like the kind of thing that could create difficult-to-understand problems if Cargo gives you two copies of a dependency only under specific and rare circumstances. (But I'm happy to be proven wrong, and I'm sure the Rust folks have thought this through more carefully than I have.)
It uses a Cargo feature meant to be used by native libraries: you typically can link them only once (or else the build will fail when it finds repeated symbols), so Cargo must ensure only one is present on the entire dependency graph. And IIRC Rayon depends on an auxiliary crate that fakes a native lib and provides the thread pool.
If this seems very hacky and convoluted, it's because it is.
I agree that how rust does it is a very nice solution.