Trouble importing files into

Can anyone help me? Here is my code.

Also when I nest the directory inside a lib directory it then tell me src/routes/ doesnt exist

Thank you!

File structure

├── Cargo.lock
├── Cargo.toml
├── src
│   ├──
│   ├──
│   └── routes
│       ├──
│       └──
├── static
│   └── abruzzo.png
└── tests

mod lib;

fn main() {

#![feature(proc_macro_hygiene, decl_macro)]

#[macro_use] use rocket::*;
use rocket_contrib::helmet::SpaceHelmet;

mod routes;

pub fn rocket_builder() -> rocket::Rocket {
    .mount("/", routes![routes::echo::echo_fn])


use rocket::*;

pub fn echo_fn(echo: String) -> String {

pub mod echo;


error[E0583]: file not found for module `routes`
 --> src\
8 | mod routes;
  | ^^^^^^^^^^^
  = help: to create the module `routes`, create file "src\lib\" or "src\lib\routes\"

error[E0433]: failed to resolve: could not find `echo` in `routes`
  --> src\
12 |     .mount("/", routes![routes::echo::echo_fn])
   |                                 ^^^^ could not find `echo` in `routes`

Some errors have detailed explanations: E0433, E0583.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `rocket-mongo` due to 2 previous errors

Normally is used as a library crate, not a module in the main executable. It should automatically be available as a dependency in your project, so remove that mod lib; and then main can call your_crate_name::rocket_builder().


The lower-level reason for your error is that as a library crate can have its submodules in the same directory, whereas a module named lib must have its submodules under lib/...


Thank you so much that work! and the explaining makes sense. I am use to doing javascript and I think I took the fact that there is so much documentation on it for granted because I am having a hard time finding documentation sometimes for these error. I should also mention this is my first time at a lower level language

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.