How do I do a basic import/include of a function from one module to another in Rust 2015?

In a mainish module (main.rs, lib.rs, or subdir/mod.rs), you need to write mod a; for all other modules that you want to use in your whole project (or in the subdir).

In any other module, you need to write use a; or use a::foo;

You’re far from the only person to be confused by this, and it’s certainly possible to do better, but any changes to the module system will get rejected as “too confusing”.

Edit: this answer was written for the “Rust 2015” language standard. Changes were made for the “Rust 2018” standard, see this blog post and the edition guide

Leave a Comment