Revisiting Rust’s modules, part 2

I like this proposal much better than the previous one! Two comments from my side:

Please, please require use to include a rs file so we prevent “stale file” horror stories like I’ve described before: Revisiting Rust’s modules . Files that wouldn’t be naturally referenced anyway are a really rare occurrence, and having to use them anyway, would be a small price to pay for confidence that Rust source code reliably compiles, no matter where and with how broken top-level build system. Unit tests or basically any form of a test or usage would catch such cases immediately during development, and lints and warning can always help.

A much more minor comment (since it’s about syntax only) is: I’d say that use X from Y; or from Y use X; is functionally exactly the same as use extern X::Y; that I’ve proposed. So I’m happy to see in this proposal, but IMO use extern (or some variation around it) as opposed to two-keyword syntax has many benefits:

  • everything module starts with use/pub use and ends with the path, so looks more uniform
  • IDEs have the easiest time completing that
  • we reuse an existing extern keyword
  • all existing use syntaxes would be applicable, and intuitive (pub use extern bzip2::Compression;, use extern bzip::read::BzDecoder as Decoder; or use extern bzip2::*; )
  • we have only one main keyword: use with natural modifiers for everything

I just can’t see disadvantages, so please consider it, or let me know what are the disadvantages that I overlook.

14 Likes