forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convenience syntax for module imports (was rust-lang#108)
Use the `mod` keyword in a module list to make the use section more concise. Originally submitted as RFC PR rust-lang#108 by @tommit.
- Loading branch information
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
- Start Date: 2014-06-06 | ||
- RFC PR #: (leave this empty) | ||
- Rust Issue #: (leave this empty) | ||
- Author: Tommit (edited by nrc) | ||
|
||
|
||
# Summary | ||
|
||
Add syntax sugar for importing a module and items in that module in a single | ||
view item. | ||
|
||
|
||
# Motivation | ||
|
||
Make use clauses more concise. | ||
|
||
|
||
# Detailed design | ||
|
||
The `mod` keyword may be used in a braced list of modules in a `use` item to | ||
mean the prefix module for that list. For example, writing `prefix::{mod, | ||
foo};` is equivalent to writing | ||
|
||
``` | ||
use prefix; | ||
use prefix::foo; | ||
``` | ||
|
||
The `mod` keyword cannot be used outside of braces, nor can it be used inside | ||
braces which do not have a prefix path. Both of the following examples are | ||
illegal: | ||
|
||
``` | ||
use module::mod; | ||
use {mod, foo}; | ||
``` | ||
|
||
A programmer may write `mod` in a module list with only a single item. E.g., | ||
`use prefix::{mod};`, although this is considered poor style and may be forbidden | ||
by a lint. (The preferred version is `use prefix;`). | ||
|
||
|
||
# Drawbacks | ||
|
||
Another use of the `mod` keyword. | ||
|
||
We introduce a way (the only way) to have paths in use items which do not | ||
correspond with paths which can be used in the program. For example, with `use | ||
foo::bar::{mod, baz};` the programmer can use `foo::bar::baz` in their program | ||
but not `foo::bar::mod` (instead `foo::bar` is imported). | ||
|
||
# Alternatives | ||
|
||
Don't do this. | ||
|
||
|
||
# Unresolved questions | ||
|
||
N/A |