Skip to content

Commit acd341b

Browse files
committed
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.
1 parent 0fc8bc0 commit acd341b

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

0000-mod.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
- Start Date: 2014-06-06
2+
- RFC PR #: (leave this empty)
3+
- Rust Issue #: (leave this empty)
4+
- Author: Tommit (edited by nrc)
5+
6+
7+
# Summary
8+
9+
Add syntax sugar for importing a module and items in that module in a single
10+
view item.
11+
12+
13+
# Motivation
14+
15+
Make use clauses more concise.
16+
17+
18+
# Detailed design
19+
20+
The `mod` keyword may be used in a braced list of modules in a `use` item to
21+
mean the prefix module for that list. For example, writing `prefix::{mod,
22+
foo};` is equivalent to writing
23+
24+
```
25+
use prefix;
26+
use prefix::foo;
27+
```
28+
29+
The `mod` keyword cannot be used outside of braces, nor can it be used inside
30+
braces which do not have a prefix path. Both of the following examples are
31+
illegal:
32+
33+
```
34+
use module::mod;
35+
use {mod, foo};
36+
```
37+
38+
A programmer may write `mod` in a module list with only a single item. E.g.,
39+
`use prefix::{mod};`, although this is considered poor style and may be forbidden
40+
by a lint. (The preferred version is `use prefix;`).
41+
42+
43+
# Drawbacks
44+
45+
Another use of the `mod` keyword.
46+
47+
We introduce a way (the only way) to have paths in use items which do not
48+
correspond with paths which can be used in the program. For example, with `use
49+
foo::bar::{mod, baz};` the programmer can use `foo::bar::baz` in their program
50+
but not `foo::bar::mod` (instead `foo::bar` is imported).
51+
52+
# Alternatives
53+
54+
Don't do this.
55+
56+
57+
# Unresolved questions
58+
59+
N/A

0 commit comments

Comments
 (0)