为什么 "no crate_relative in serve" 而 rust rocket_contrib?

Why is "no crate_relative in serve" when rust rocket_contrib?

我正在尝试通过我惯用的方法和 运行 示例来学习一些 Rust。

rust_contrib api 文档上的这个页面让我觉得我可以像这样提供静态文件 https://api.rocket.rs/master/rocket_contrib/serve/struct.StaticFiles.html...

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();
}

相反,编译器对我咆哮...

    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 看起来像这样...

[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"]

我做了什么得罪锈神了?

谢谢

您正在查看的文档是针对 Rocket 的 master 分支的,该分支目前代表尚未发布的 0.5 版本。 Rocket 0.4.5版本没有crate_relative.

对于解决方法,您可以查看 0.4 docs 的说明:

use rocket_contrib::serve::StaticFiles;

fn main() {
    rocket::ignite()
        .mount("/", StaticFiles::from(concat!(env!("CARGO_MANIFEST_DIR"), "/static")))
        .launch();
}