I am using the (so far, terrific!) Fluent Templates crate. I'm using it with handlebars and I'm getting a doozy of a type mismatch build error that I can't quite grok.
Here's what I'm doing:
let loader = ArcLoader::builder(
"resources/locales",
langid!("en-US")
)
.build()
.unwrap();
let mut handlebars = Handlebars::new();
let helper = Box::new(FluentLoader::new(&loader));
handlebars.register_helper("fluent", helper);
error[E0277]: expected a `std::ops::FnOnce<(&handlebars::render::Helper<'reg, 'rc>, &'reg handlebars::registry::Registry<'reg>, &'rc handlebars::context::Context, &mut handlebars::render::RenderContext<'reg, 'rc>, &mut dyn handlebars::output::Output)>` closure, found `fluent_templates::loader::FluentLoader<&fluent_templates::loader::arc_loader::ArcLoader>`
Flattened out a bit:
error[E0277]: expected a `std::ops::FnOnce<(
&handlebars::render::Helper<'reg, 'rc>,
&'reg handlebars::registry::Registry<'reg>,
&'rc handlebars::context::Context,
&mut handlebars::render::RenderContext<'reg, 'rc>,
&mut dyn handlebars::output::Output
)>` closure, found `fluent_templates::loader::FluentLoader<&fluent_templates::loader::arc_loader::ArcLoader>`
I can see that that is the signature of the call method in the HelperDef trait, but I can't for the life of me figure out why the struct I'm passing to register_helper() doesn't fit the expected type.
Your let helper=Box::new(...) line is creating a boxed raw instance instead. Either removing the intermediate variable helper or explicity identifying its type (let helper:Box<dyn Helperdef + Send + Sync>=...) should fix the problem.
In case anyone else stumbles across this issue, the problem was that the Handlebars support is locked behind a feature in the fluent-templates crate. The fluent templates handlebars helper didn't exist in my project, because I didn't include that feature, so rustc was trying to match my call to the closest implementation of HelperDef it could, which was the one for passing a raw function as a helper.