Nested imports with use

Minimum Rust version: 1.25

A new way to write use statements has been added to Rust: nested importgroups. If you’ve ever written a set of imports like this:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. use std::fs::File;
  4. use std::io::Read;
  5. use std::path::{Path, PathBuf};
  6. }

You can now write this:

  1. #![allow(unused_variables)]
  2. fn main() {
  3. mod foo {
  4. // on one line
  5. use std::{fs::File, io::Read, path::{Path, PathBuf}};
  6. }
  7. mod bar {
  8. // with some more breathing room
  9. use std::{
  10. fs::File,
  11. io::Read,
  12. path::{
  13. Path,
  14. PathBuf
  15. }
  16. };
  17. }
  18. }

This can reduce some repetition, and make things a bit more clear.