0

I am having some trouble with moving a function into a separate file when using the rocket library.

I am able to compile and run the getting-started-example from rockets web page, like this:

// main.rs
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;

#[get("/")]
pub fn index() -> &'static str { "Hello, world!" }

fn main() { rocket::ignite().mount("/", routes![index]).launch(); }

But if I move the index() function into its own file, in the same directory, like this:

// main.rs
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use] extern crate rocket;

mod index;

fn main() { rocket::ignite().mount("/", routes![index]).launch(); }
// index.rs 
#[get("/")]
pub fn index() -> &'static str { "Hello, world!" }

I am then presented with the error message:

error[E0425]: cannot find value `static_rocket_route_info_for_index` in this scope
 --> src/main.rs:8:41
  |
8 |     rocket::ignite().mount("/", routes![index]).launch();
  |                                         ^^^^^ not found in this scope
  |
help: consider importing this static
  |
5 | use crate::index::static_rocket_route_info_for_index;
  |

What does this mean in this context and how do i fix it?

SørenHN
  • 566
  • 5
  • 20
  • 1
    There's a confusion between the `index` function and the `index` module. You should either `use index::index;` or write `routes![index::index]`. – Jmb Feb 22 '21 at 08:01

1 Answers1

0

As @Jmb commented, the problem was that the file index and the function index got mixed up. So the solution was to specify the function as index::index.

SørenHN
  • 566
  • 5
  • 20