Actix Handlebars Example | Anonymous lifetime | Unresolved method

Hi,
I'm currently trying to implement something simple using actix.
I found the examples repository which is quiet nice although I tried two examples so far and none of them compiled using the up to date versions of the corresponding crates and rust 1.42.0.

Currently I'm trying out the handlebars example because I'm familiar with handlebars (in general, not the rust implementation):

https://github.com/actix/examples/blob/master/template_handlebars/src/main.rs

I get two different compile errors which I'm unable to understand.
In the docs for handlebars I couldn't find a mention of the lifetime specifier for the Handlebars struct. Still, the compiler complains about it being missing:

error[E0726]: implicit elided lifetime not allowed here
  --> src/main.rs:16:30
   |
16 | async fn index(hb: web::Data<Handlebars>) -> HttpResponse {
   |                              ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>

Even more confusing for me is the error:

error[E0599]: no method named `register_templates_directory` found for struct `handlebars::registry::Registry<'_>` in the current scope
  --> src/main.rs:46:10
   |
46 |         .register_templates_directory(".html", "./static/templates")
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: there is a method with a similar name: `register_template_file`

That's because register_templates_directory is neither deprecated nor missing. So why doesn't the compiler find it?

My Cargo.toml looks like this:

[dependencies]
actix-web = "3.0.0-alpha.1"
actix-rt = "1.0.0"
serde = "1.0.104"
serde_derive = "1.0.104"
serde_json = "1.0.48"
handlebars = "3.0.1"

Thanks for any help!
Best regards

Your provided link to the handlebars doc is to version 3.1.0-beta.1, whereas your Cargo.toml uses 3.0.1. Please ensure that you are viewing the documentation for the crate you are using. That said, if you update the link to this, the function still exists.

I'm not quite sure why you're getting the error you're getting. As for the lifetime, you can see it by selecting "Show declaration" at the top of the page.

It's also quite confusing how they have reexported a struct named Registry as Handlebars... You can see this by pressing [src] on the page.

Can you try compiling the doc locally with cargo doc and checking that version?

1 Like

I found the solution in the source code.
My Cargo.toml was missing the dir_source feature:

handlebars = {version="3.0.1", features=["dir_source"]}

This is stated in the source code here:

The actix example is missing it though, because it uses handlebars version 2.0 which didn't require turning on the feature:

Thanks for your advice @alice

1 Like

Tricky!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.