Problems when re-exporting crates

I have three crates: foo, bar and baz, and foo is a common used thrid-party crate, I import and use it in crate bar.

And now I want that whoever uses my crate bar, he/she can use foo as well without manually import it( to avoid the version conflict and for the sake of easy using), so I write this line in the top module(lib.rs) of crate bar:

pub use foo;

But I found that if I want to use functions in foo, for example writing codes in crate baz, I cannot use foo::f, but bar::foo::f, this is not exactly what I want.

So how to re-export crates, to let users crate/module name directly?

You can't. If user wants to use foo as a root name, they must somehow make it available themselves - either by adding foo to dependencies, or by use bar::foo. The only thing you control is what is available under your own crate's namespace.

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.