1

I'm trying to learn some rust by my usual method of flailing around and running examples.

This page on the rust_contrib api docs makes me think I can serve static files https://api.rocket.rs/master/rocket_contrib/serve/struct.StaticFiles.html like this...

use rocket_contrib::serve::StaticFiles;
use rocket_contrib::serve::crate_relative;

...

fn main() {
    rocket::ignite()
        .mount("/content", StaticFiles::from(crate_relative!("content")))
        .mount("/", routes![index])
        .mount("/api", routes![hello, new_book])
        .register(catchers![not_found]) 
        .attach(Template::fairing())
        .launch();
}

Instead the compiler barks at me...

    error[E0432]: unresolved import `rocket_contrib::serve::crate_relative`
 --> src/main.rs:9:5
  |
9 | use rocket_contrib::serve::crate_relative;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `crate_relative` in `serve`

Cargo.toml looks like this...

[package]
name = "rocket-web"
version = "0.1.0"
authors = ["Nunya B. Znas <dontworry@bout.it>"]
edition = "2018"

[dependencies]
rocket = "0.4.5"
serde = {version = "1.0", features = ["derive"]}

[dependencies.rocket_contrib]
version = "0.4.5"
features = ["handlebars_templates", "tera_templates"]

What have I done to offend the rust gods?

Thanks

BenMaGoo
  • 45
  • 1
  • 8

1 Answers1

4

The docs you are looking at are for Rocket's master branch, which currently represents the yet-to-be-released 0.5 version. Rocket version 0.4.5 does not have crate_relative.

For a workaround, you can see how the 0.4 docs say to do it:

use rocket_contrib::serve::StaticFiles;

fn main() {
    rocket::ignite()
        .mount("/", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static")))
        .launch();
}
kmdreko
  • 42,554
  • 6
  • 57
  • 106