建筑火箭车把例如,当未解决的导入模板

问题描述 投票:3回答:1

我无法让火箭handlebars example工作。这是我的Cargo.toml依赖关系:

[dependencies]
rocket = "*"
rocket_codegen = "*"
rocket_contrib = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

这些错误:

error[E0432]: unresolved import `rocket_contrib::Template`
  --> src\main.rs:29:5
   |
29 | use rocket_contrib::Template;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^ no `Template` in the root

error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^

第一个错误查找Template并不能找到它。在这个例子中的git repo,它不存在。这怎么可能,示例工程?我相信,在我main.rs锈代码是好的,这是相同的例子。我认为这只是一个依赖的问题。

我改变了我的Cargo.toml到:

[dependencies]
rocket = "*"
rocket_codegen = "*"
serde = "*"
serde_json = "*"
serde_derive = "*"

[dependencies.rocket_contrib]
version = "*"
features = ["handlebars_templates"]

现在,我得到这些错误:

error[E0599]: no method named `attach` found for type `rocket::Rocket` in the current scope
  --> src\main.rs:62:10
   |
62 |         .attach(Template::fairing())
   |          ^^^^^^

error[E0599]: no associated item named `fairing` found for type `rocket_contrib::Template` in the current scope
  --> src\main.rs:62:17
   |
62 |         .attach(Template::fairing())
   |                 ^^^^^^^^^^^^^^^^^
rust rust-rocket
1个回答
5
投票

这是因为丢失了handlebars_templates功能。您可以see this in the example's Cargo.toml

[dependencies.rocket_contrib]
version = "*" # Not a good idea to use * as version
features = ["handlebars_templates"]
© www.soinside.com 2019 - 2024. All rights reserved.