Skip to content

Commit 0138d87

Browse files
committed
Document pub use foo::* in the reference manual
r=brson Closes #3788
1 parent 80d6bc8 commit 0138d87

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/rust.md

+15
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,25 @@ fn main() {
847847

848848
Like items, `use` declarations are private to the containing module, by default.
849849
Also like items, a `use` declaration can be public, if qualified by the `pub` keyword.
850+
Such a `use` declaration serves to _re-export_ a name.
850851
A public `use` declaration can therefore be used to _redirect_ some public name to a different target definition,
851852
even a definition with a private canonical path, inside a different module.
852853
If a sequence of such redirections form a cycle or cannot be unambiguously resolved, they represent a compile-time error.
853854

855+
An example of re-exporting:
856+
~~~~
857+
mod quux {
858+
mod foo {
859+
pub fn bar() { }
860+
pub fn baz() { }
861+
}
862+
863+
pub use foo::*;
864+
}
865+
~~~~
866+
867+
In this example, the module `quux` re-exports all of the public names defined in `foo`.
868+
854869
### Functions
855870

856871
A _function item_ defines a sequence of [statements](#statements) and an optional final [expression](#expressions), along with a name and a set of parameters.

0 commit comments

Comments
 (0)