Depending on the same crate twice

Is it possible to use the same crate twice, in two different instances? The crates have globals, and I need two different instances of them.

No, I would rather not just get rid of the globals.

If that is impossible, is it possible to use the same files in two different crates in the same package? (without duplicating the files.)

Well, you can rename dependencies as described in the documentation here. It's designed for pulling in two versions of the same crate, but I figure it works for your situation as well (haven't tried it myself, though).

Does it work for crates in the same package?

If you want to do this all within one package, you could create two different modules that are compiled from the same source files. (These modules would both be within the same crate; a Cargo package can't contain multiple library crates.)

#[path = "foo/"]
mod a;

#[path = "foo/"]
mod b;
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.