Re-exports

When structuring your code in deeply nested modules, using different parts can become quite tedious, since you may have many different, pretty long logical paths to the code you want. Also, you sometimes might want to offer a different interface than the actual code structure provides. The prime example is factoring out code into submodules, where the access path seen from the outside changes. To that end, you can re-export an item back into your current module by just making a public use statement.

Let's assume the directory structure from the module example. If we want to make SomeStruct available directly from the outer_module, we just have to add a statement to that module:

// Doesn't need to be public if you don't want direct access
mod inner_module;

// Re-export
pub use inner_module::SomeStruct;

We can now refer to it directly from the outer module. The main file can use it like this:

mod outer_module;

fn example2() {
  let re_exported = outer_module::SomeStruct;
}