One of the things that's been criticized by newbies in Rust is the file include mechanism. About 2 days ago, I spent around 5 hours on how I was supposed to include a file that was referenced deep down in a directory tree. The docs didn't help, as they were simple structures. Here I'll show you how you can include your code in different parts of the application, even when the structure is complex, and save you hours on how to do this supposedly trivial task. I'm going to refer to traits, modules, enums, functions, structs as "resources" in general. I'd also like to share with you a video from as this was the resource that taught me how to properly include the resources. TensorProgramming "Rust 2018 - Modules, External Crates, Submodules, Paths and Visibility Modifier"s by TensorProgramming - https://www.youtube.com/watch?v=U8uhW9bFm-8 An example repo can be found here: https://github.com/superjose/rust-include-files-example There's no such thing as a "file" when you reference your resource. Rust doesn't see files as files, but it sees them as modules and files inside folders as sub-modules. Therefore you can't just reference them directly with a simple import or drilled namespacing a la JavaScript or C# and use them right away. You need to create a tree of (Called barrelling in the JS world) that expose these modules to the outer ones and (See the bullet points down below) allow them to be discovered and consumed. pub mod file_name How to include a module (file) Let's suppose we have the following structure (You can grab this from the ). repo And you'd like to include several functions from modules scattered inside the directory into our file: /src/house main.rs house; welcome_home; crate::house::diner; house::bathroom::sink::wash_face; house::kitchen::prepare::food_preparation::prepare_food; () { user = ; building::lobby::arrive_lobby(); welcome_home::run(user); house::bathroom::shower::take_shower(house::bathroom::shower::ShowerTemperature::Cold); wash_face(); house::bathroom::toilet::use_toilet(); prepare_food(); diner::eat(); } building { lobby { ( ) () { ( ); } } } mod // Please, do not use hyphens as this is proven to have an // inconsistent behavior. // https://github.com/rust-lang/book/issues/1709 // https://rust-lang.github.io/rfcs/0940-hyphens-considered-harmful.html // https://stackoverflow.com/a/57535534/1057052 #[path = ] "./welcome-home.rs" mod // Includes the function directly // When using crate, you use the root directory to include everything. use use use fn main let "Jose" // https://doc.rust-lang.org/reference/visibility-and-privacy.html /** * From the docs (Link above) * * By default, everything in Rust is private, with two exceptions: * Associated items in a pub Trait are public by default; Enum * variants in a pub enum are also public by default. When an * item is declared as pub, it can be thought of as being accessible * to the outside world. */ mod pub mod pub in crate fn arrive_lobby println! "You have arrived to the lobby" To include a file next to the main.rs file you just specify and the name of the file (without the .rs extension). E.g: mod . In this case welcome_home does not match the name of the file ( - this was to showcase it's possible not that it should be done , therefore we can help Rust's compiler to identify it by providing a #path directive. Then we can reference in our code to call the run function directly. mod welcome_home welcome-home.rs Avoid using hyphens in naming everything; ) welcome_home::run() To use a mod that exists inside the file, you can just type its name as namespace and drill down to the resource you're looking for. Understand that if the module is not public you won't be able to access it within your file. Check for more information. If you'd like to include the function. Since it's in the same file you can just and the module is visible. Rust's visibility and privacy reference arrive_lobby building::lobby::arrive_lobby You can use a resource directly by specifying it with the keyword. This means that you don't need to write to use the function, but simply . use house::bathroom:sink::wash_face() wash_face() In case of which is found in first create a house.rs file at the root level directory or a mod.rs file in /src/house/mod.rs. Inside it specify the names of the folders that are included inside /src/house: . Create a file in and inside it specify the modules (file names without the .rs extension) inside : Note the modifier as this is what gives visibility outside of the speicified file. Then include them in the code via . wash_face house::bathroom::sink::wash_face pub mod bathroom bathroom.rs /src/house/bathroom.rs /src/house/bathroom pub mod sink; pub mod shower; pub mod toilet; pub use house::bathroom::sink::wash_face After , if you type , you're telling the compiler to start looking from the root directory. use crate If you reference a resource via a mod and that resource is deeply nested, you only specify the first level of the module, and then drill it down. E.g: In case of function and enum, I only specified , and then drilled down the namespaces with the double colon (::) until I reach it. house::bathroom::shower::take_shower(house::bathroom::shower::ShowerTemperature::Cold) mod house Including files or modules from another folder, directory or submodule This is maybe the trickiest and most unnatural way for all new people to Rust to reference modules in other files. The function is an example of a deeply nested function. I encourage you to see the to understand better how everything works. wash_face repo Rust You need to with the name of the directory you'd like to access, and place it next to the directory you'd like to access. follows a convention: create a file You would then need to expose each of the files inside the directory that you'd like the compiler to make it accessible: Example: I'd like to access the contents of , , and inside the folder. shower.rs sink.rs toilet.rs /src/house/bathroom First, I'd have to create a file that would make visible or barrel and files. Inside it I'd specify the name of each of the files as public modules: /src/house/bathroom.rs shower.rs, sink.rs toilet.rs shower; sink; toilet; // Contents of /src/house/bathroom.rs pub mod pub mod pub mod Then, I'd need to expose this file from the directory. For that, I'd need to create a file, that would export the file that I just defined now. bathroom.rs /src/house /src/house.rs bathroom.rs bathroom; diner; kitchen; // Contents of /src/house/mod.rs or /src/house.rs pub mod pub mod pub mod As you can see makes file visible. Note the convention: pub mod bathroom bathroom.rs pub mod file_name_without_rs_extension You need to do this you'd like to make a module (file) visible to the outer module (directory/folder). everytime : You'd see in the repo, and in the picture above, that there are files; In versions before Rust 2018, the only way for Rust to discover these directories was for them to specify inside the directory. Note mod.rs mod.rs This became problematic because if you wanted to specify a file with the same name of the directory, the compiler would get confused. That's why starting Rust 2018 (Look for the line which says in your file). edition = "2018" cargo.toml In this example is the same as You can create any of those files and it would work. /src/house/mod.rs /src/house.rs Including other sibling modules (files) within submodules To include sibling files within submodules, such as the /src/house/ within the file you can get to lasagna.rs by using the keyword in your statements. main_dish/lasagna.rs diner/mod.rs self use dessert; main_dish; self::main_dish::lasagna; () { lasagna::eat_lasagna(); candy = dessert::candy::Candy::new_chocolate( ); dessert::candy::eat_dessert(candy); } pub mod pub mod use // use super::diner::main_dish::lasagna; pub fn eat let 10 For example, the code below uses self to navigate relatively to the current module's location, and then drill it to the . main_dish::lasagna You can also use and that will start from the parent module. super Some things you should know: Prefer underscore (snake case) over hyphens. The latter tend to create problems . (1) (2) For exposing rust modules (files) inside a directory (folder) you need to create a folder with the directory name and export in the form of to allow the compiler to use the file. pub mod file_name_inside_folder References Rust 2018 - Modules, External Crates, Submodules, Paths and Visibility Modifiers by TensorProgramming - https://www.youtube.com/watch?v=U8uhW9bFm-8 (Best resource that explains how to include everything) Including crates with hyphen vs underscore debate: https://github.com/rust-lang/cargo/issues/2775 https://doc.rust-lang.org/reference/visibility-and-privacy.html https://github.com/rust-lang/book/issues/1709 https://stackoverflow.com/questions/57535061/how-to-use-another-file-in-rust-module-with-hyphens-in-it- https://users.rust-lang.org/t/how-to-call-a-function-in-another-file-but-the-same-crate/15214- https://stackoverflow.com/a/26390046/1057052 https://stackoverflow.com/questions/45519176/how-do-i-use-or-import-a-local-rust-file https://stackoverflow.com/questions/26224947/how-do-i-do-a-basic-import-include-of-a-function-from-one-module-to-another-in-r