January 2019
Beginner to intermediate
554 pages
13h 31m
English
Re-exports allows one to selectively expose items from a module. We were already using the convenience of reexports when we used the Option and Result types. Re-exports also helps in reducing the import path one has to write if the module is created a nested directory containing many submodules.
For example, here we have a sub module named bar.rs from a cargo project we created called reexports:
// reexports_demo/src/foo/bar.rspub struct Bar;
The Bar is a publicly exposed struct module under src/foo/bar.rs. If the user wants to use Bar in their code, they will have to write something like the following:
// reexports_demo/src/main.rsuse foo::bar::Bar;fn main() { }
The above use statement is quite verbose. When you have a lot ...
Read now
Unlock full access