I've been learning the basics of Rust and tripped over the pub use in modules that is used to re-export things. Since I'm totally new to the language I wanted to ask here first, before opening an issue on the documentation.
So, in the book there is this example on re-exporting items from a module.
If I use it like it's documented:
mod quux {
pub use quux::foo::{bar, baz};
pub mod foo {
pub fn bar() {}
pub fn baz() {}
}
}
fn main() {
quux::bar();
quux::baz();
}
It does not compile.
Failed to resolve: use of undeclared type or module quux
If I replace the pub use line with:
pub use self::foo::{bar, baz};
It does work. Is that correct and the inteded way? Or am I missing something? There is an example in the old 1.0 documentation that does a better job at explaining the concept imo by using multiple module in different files.
or an absolute path that refers to an external crate: use ::name...
This is, by the way, why I favor the syntax with a leading :: to refer to external crates, so that if I spot an ambiguous path I can start assuming it is a relative path. It makes reading an unknown code base so much easier (no need to go check the Cargo.toml to know which external crates are in scope)
Is there a recommended style for organizing mod, use, and pub use lines?
I always run cargo fmt on my code and I like how it automatically alphabetizes items. But I also try to create different blocks for use of external crates (first) and use of in inteneral items (second block). I start to get confused when deciding how to organize pub use and pub mod ... anyway
Is there some standard way to group/organize these lines so I don't have to think about it?