如何在 Rust 的稳定版本上使用 rocket

How to use rocket on stable release of Rust

我正在尝试使用 rustc 的稳定版本来编译 rocket web 应用程序。 rocket crate 编译正常,但我想使用来自 rocket_contrib 的静态文件服务器。我的 Cargo.toml 文件如下所示:

[dependencies]
rocket = "0.5.0-rc.1"

[dependencies.rocket_dyn_templates]
version = "0.1.0-rc.1"
features = ["handlebars"]

[dependencies.rocket_contrib]
version = "0.4.10"
default-features = false
features = ["serve"]

当我尝试 运行 cargo build 时出现以下错误:

Error: Pear requires a 'dev' or 'nightly' version of rustc.
Installed version: 1.52.1 (2021-05-09)
Minimum required:  1.31.0-nightly (2018-10-05)

从 Rocket 的 0.5 版开始,您将不会使用 rocket_contrib,因为这个功能被拆分为已经在核心包中或移动到单独的包中的功能。 this revision (see also issue 1659) 中的注释提供了更多详细信息:

This follows the completed graduation of stable contrib features into core, removing 'rocket_contrib' in its entirety in favor of two new crates. These crates are versioned independently of Rocket's core libraries, allowing upgrades to dependencies without consideration for versions in core libraries.

'rocket_dyn_templates' replaces the contrib 'templates' features. While largely a 1-to-1 copy, it makes the following changes:

  • the 'tera_templates' feature is now 'tera'
  • the 'handlebars_templates' feature is now 'handlebars'
  • fails to compile if neither 'tera' nor 'handlebars' is enabled

'rocket_sync_db_pools' replaces the contrib 'database' features. It makes no changes to the replaced features except that the database attribute is properly documented at the crate root.

简而言之,您需要将代码从 rocket_contrib 迁移出去。一旦 v0.5 确定发布,可能会提供更好的指南,但在此之前,您可以在 core documentation and respective Cargo feature list.

中查找 rocket_contrib 中曾经可用的功能