4

I am unable to get the Rocket handlebars example to work. These are my Cargo.toml dependencies:

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

The errors:

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())
   |          ^^^^^^

The first error looks for Template and can't find it. In the git repo of the example, it doesn't exist. How is it possible that the example works? I am sure that the Rust code in my main.rs is ok, it's the same as in the example. I think it's only a dependency problem.

I changed my Cargo.toml to:

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

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

Now I get these errors:

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())
   |                 ^^^^^^^^^^^^^^^^^
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Kian
  • 695
  • 2
  • 11
  • 23

1 Answers1

6

You are missing the handlebars_templates feature. You can see this in the example's Cargo.toml:

[dependencies.rocket_contrib]
version = "*" # Not a good idea to use * as version
features = ["handlebars_templates"]
Peter Hall
  • 53,120
  • 14
  • 139
  • 204
belst
  • 2,285
  • 2
  • 20
  • 22