Rocket, Fluent and Handlebars: E0515 & type mismatch in function arguments

Oh, it's me again. Hello.

I played with rocket and handlebars some time ago. My code has previously worked. Now I did a cargo update and are a bit at loss figuring out what has changed.

Cargo.toml

[package]
name = "t"
version = "1.0.0"
edition = "2018"

[dependencies]
rocket =  { version = "*", features = ["tls"] }
lazy_static = "*"
handlebars = "*"
fluent = "*"
fluent-bundle = "*"
fluent-locale = "*"

[dependencies.rocket_contrib]
version = "*"
default-features = false
features = ["handlebars_templates"]

Error one: how could one rewrite the lazy_static fluent_bundle: (Vec<String>, FluentBundle<'static>) so that it is usable in fn t?

error[E0515]: cannot return value referencing local variable `resource`
   --> src/main.rs:131:2
    |
128 |         bundle.add_resource(&resource).expect("Failed to add FTL resources to the bundle.");
    |                             --------- `resource` is borrowed here
...
131 |     (locales,bundle)
    |     ^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function

Error two: remove the comment // for the handlebars helper t...

engines.handlebars.register_helper("t", Box::new(t));

...then another error occurs:

error[E0631]: type mismatch in function arguments
   --> src/main.rs:138:44
    |
23  | / fn t(
24  | |     h: &Helper<'_, '_>,
25  | |     _: &Handlebars,
26  | |     _: &Context,
...   |
67  | |     Ok(())
68  | | }
    | |_- found signature of `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> fn(&'r handlebars::render::Helper<'s, 't0>, &'t1 handlebars::registry::Registry, &'t2 handlebars::context::Context, &'t3 mut handlebars::render::RenderContext<'t4>, &'t5 mut (dyn handlebars::output::Output + 't5)) -> _`
...
138 |               engines.handlebars.register_helper("t", Box::new(t));
    |                                                       ^^^^^^^^^^^ expected signature of `for<'r, 'reg, 'rc, 's, 't0> fn(&'r handlebars::render::Helper<'reg, 'rc>, &'reg handlebars::registry::Registry, &'rc handlebars::context::Context, &'s mut handlebars::render::RenderContext<'reg>, &'t0 mut (dyn handlebars::output::Output + 't0)) -> _`
    |
    = note: required because of the requirements on the impl of `handlebars::helpers::HelperDef` for `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> fn(&'r handlebars::render::Helper<'s, 't0>, &'t1 handlebars::registry::Registry, &'t2 handlebars::context::Context, &'t3 mut handlebars::render::RenderContext<'t4>, &'t5 mut (dyn handlebars::output::Output + 't5)) -> std::result::Result<(), handlebars::error::RenderError> {t}`
    = note: required for the cast to the object type `dyn handlebars::helpers::HelperDef`

error[E0631]: type mismatch in function arguments
   --> src/main.rs:138:44
    |
23  | / fn t(
24  | |     h: &Helper<'_, '_>,
25  | |     _: &Handlebars,
26  | |     _: &Context,
...   |
67  | |     Ok(())
68  | | }
    | |_- found signature of `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> fn(&'r handlebars::render::Helper<'s, 't0>, &'t1 handlebars::registry::Registry, &'t2 handlebars::context::Context, &'t3 mut handlebars::render::RenderContext<'t4>, &'t5 mut (dyn handlebars::output::Output + 't5)) -> _`
...
138 |               engines.handlebars.register_helper("t", Box::new(t));
    |                                                       ^^^^^^^^^^^ expected signature of `fn(&handlebars::render::Helper<'reg, 'rc>, &'reg handlebars::registry::Registry, &'rc handlebars::context::Context, &mut handlebars::render::RenderContext<'reg>, &mut dyn handlebars::output::Output) -> _`
    |
    = note: required because of the requirements on the impl of `handlebars::helpers::HelperDef` for `for<'r, 's, 't0, 't1, 't2, 't3, 't4, 't5> fn(&'r handlebars::render::Helper<'s, 't0>, &'t1 handlebars::registry::Registry, &'t2 handlebars::context::Context, &'t3 mut handlebars::render::RenderContext<'t4>, &'t5 mut (dyn handlebars::output::Output + 't5)) -> std::result::Result<(), handlebars::error::RenderError> {t}`
    = note: required for the cast to the object type `dyn handlebars::helpers::HelperDef`

error: aborting due to 2 previous errors

That's it. I'm lost. I can see that the second parameter is &Handlebars once but in the error message I see "handlebars::registry::Registry". But Registry seems to be private...

links: Rust Playground
or: Code shared from the Rust Playground ยท GitHub

Any help is really appreciated. Thanks.

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