Skip to content

Commit

Permalink
Add use_nested_groups to the newest features appendix
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Feb 1, 2018
1 parent 4bbc377 commit 0b562f6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions second-edition/src/appendix-06-newest-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,37 @@ fn main() {
assert_eq!(result, 20);
}
```


## Nested groups in `use` declarations

If you have a complex module tree with many different submodules and you need
to import a few items from each one, it might be useful to group all the
imports in the same declaration to keep your code clean and avoid repeating the
base modules' name.

The `use` declaration supports nesting to help you in those cases, both with
simple imports and glob ones. For example this snippets imports `bar`, `Foo`,
all the items in `baz` and `Bar`:

```rust
# #![allow(unused_imports, dead_code)]
#
# mod foo {
# pub mod bar {
# pub type Foo = ();
# }
# pub mod baz {
# pub mod quux {
# pub type Bar = ();
# }
# }
# }
#
use foo::{
bar::{self, Foo},
baz::{*, quux::Bar},
};
#
# fn main() {}
```

0 comments on commit 0b562f6

Please sign in to comment.