Rust confused file system

I read tons of document but I can't understand this file/module system of Rust. I'm trying to seperate modules but I can't. Because everytime I'm getting error and says:

  • can't find crate
  • file not found for module modules
  • unresolved import crate::modules
  • file not found for module test1
  • unresolved import modules
  • failed to resolve: there are too many initial supers.
  • unused import: modules::mod


I have a project that name is "Project1". And this project contains two folder: Src(this folder contains as you know) and Modules (I created this)
Src folder contains and Modules folder contains,,

Now I'm asking you. How I include this "modules" file in the ? Is this file system really hard to understand or am I only who don't understand this ?

I tried these:

  • use modules
  • mod modules
  • extern crate modules
  • use crate::modules
  • use super::modules
  • use self::modules
  • mod modules/test1
  • mod modules/
  • mod
  • mod test1

If you have not read this yet, you may want to read it first. If you have already read it and not understand something, ask about the part that you not understand here!

1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Sorry if my words is not good (English is not my native). But that chapter is written for modules/crate in Rust. If I say something, I just repeat information from it. If you have a code a repo somewhere, then people can point out where is the problem for you.

1 Like

For example, you can have a repo like this. Then, someone may come up with a help like this.

1 Like

Here's another good blog post on how the module system relates to the file system:


Based on what you described you should have:

pub mod modules;

// modules/
pub mod test1;
pub mod test2;

Now you can import things from modules using use crate::modules::foo and stuff from test1 using use crate::modules::test1::bar.

Note that you wrote your modules folder in upper case, but it should be lower case.

What is unusual in your setup is that "modules" directory is alongside "src" directory, instead of being inside it. This is the reason why all your attempts failed.

This is solvable by adding #[path = "../modules/"] attribute before referencing "modules" module in

If I understand correctly your setup is the following:

├── modules
│   ├──
│   ├──
│   └──
└── src

For example, following file contents:


mod test1;
mod test2;

pub use test1::f1;
pub use test2::f2;


pub fn f1() {
    println!("I am in test1 module!")


pub fn f2() {
    println!("I am in test2 module!")


#[path = "../modules/"]
mod modules;
use modules::{f1, f2};

fn main() {


I am in test1 module!
I am in test2 module!