Skip to content

Commit

Permalink
Convenience syntax for module imports (was rust-lang#108)
Browse files Browse the repository at this point in the history
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
nrc committed Jul 16, 2014
1 parent 0fc8bc0 commit acd341b
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions 0000-mod.md
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

0 comments on commit acd341b

Please sign in to comment.