XAMPPRocky / fluent-templates

Easily add Fluent to your Rust project.
Apache License 2.0
136 stars 28 forks source link

Handlebars example from the docs appears not to compile #10

Closed MrTact closed 4 years ago

MrTact commented 4 years ago

I have created a demo repo which contains the complete implementation of the handlebars demo from the docs.

When I try to build this repo, I get a pretty gnarly type conversion error:

error[E0277]: expected a `std::ops::Fn<(&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::static_loader::StaticLoader>`
  --> src/main.rs:15:42
   |
15 |     handlebars.register_helper("fluent", Box::new(FluentLoader::new(&*LOCALES)));
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<(&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::static_loader::StaticLoader>`
   |
   = help: the trait `for<'r, 'reg, 'rc, 's, 't0> std::ops::Fn<(&'r handlebars::render::Helper<'reg, 'rc>, &'reg handlebars::registry::Registry<'reg>, &'rc handlebars::context::Context, &'s mut handlebars::render::RenderContext<'reg, 'rc>, &'t0 mut (dyn handlebars::output::Output + 't0))>` is not implemented for `fluent_templates::loader::FluentLoader<&fluent_templates::loader::static_loader::StaticLoader>`
   = note: required because of the requirements on the impl of `handlebars::helpers::HelperDef` for `fluent_templates::loader::FluentLoader<&fluent_templates::loader::static_loader::StaticLoader>`
   = note: required for the cast to the object type `dyn handlebars::helpers::HelperDef + std::marker::Send + std::marker::Sync`

I would have submitted a PR for this, but frankly it's a bit beyond my understanding at the present time.

Note that I tried to build this both with 1.44 and nightly, so I don't think it's a recent feature that the lib is relying on.

XAMPPRocky commented 4 years ago

@MrTact Thank you for your issue! Have you ensured that you have enabled the handlebars feature? it is not enabled by default.

fluent-templates = { version = "*", features = ["handlebars"] }
MrTact commented 4 years ago

I am positive that I have not. That’s probably it! I missed that completely. Will let you know shortly.

TK On Jun 20, 2020, 7:02 PM -0500, XAMPPRocky notifications@github.com, wrote:

@MrTact Thank you for your issue! Have you ensured that you have enabled the handlebars feature? it is not enabled by default. fluent-templates = { version = "*", features = ["handlebars"] } — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

MrTact commented 4 years ago

Yuuup, that was it. I'm probably going to submit a PR to update the docs to make this more explicit, to help out the next person with my level of n00bness. Would you rather I leave this issue open & target the PR at it, or close the issue and just submit the PR?

XAMPPRocky commented 4 years ago

@MrTact I would make a PR and mention that it closes this issue in the description.

MrTact commented 4 years ago

@XAMPPRocky as it happens, you already made the changes I was going to make: https://github.com/XAMPPRocky/fluent-templates/commit/a5aaea8bd8472b063033355a855e16112d1cd12f. However, these changes are not showing up on the docs.rs page for the crate, for some reason: https://docs.rs/fluent-templates/0.5.10/fluent_templates/#handlebars

XAMPPRocky commented 4 years ago

@MrTact It needs to also be added to the src/lib.rs to show up in docs.rs they're not the same file.

MrTact commented 4 years ago

Gotcha -- I'll take care of that, then.

videni commented 3 years ago

@XAMPPRocky I am sure fluent-templates = { version = "*", features = ["handlebars"] } is added in my cargo.toml, but still has this error.