You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/rust.md
+15
Original file line number
Diff line number
Diff line change
@@ -847,10 +847,25 @@ fn main() {
847
847
848
848
Like items, `use` declarations are private to the containing module, by default.
849
849
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.
850
851
A public `use` declaration can therefore be used to _redirect_ some public name to a different target definition,
851
852
even a definition with a private canonical path, inside a different module.
852
853
If a sequence of such redirections form a cycle or cannot be unambiguously resolved, they represent a compile-time error.
853
854
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
+
854
869
### Functions
855
870
856
871
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