XAMPPRocky/fluent-templates
View on GitHubExample "LOCALES.lookup_with_args" results in a compile-time error
Open
#99 opened on Nov 1, 2025
bugdocumentationgood first issuehelp wanted
Repository metrics
- Stars
- (167 stars)
- PR merge metrics
- (PR metrics pending)
Description
Hello,
When running the third example in the README, using fluent_templates 0.13.2, I'm getting a compile-time error as shown below (specifically on the lines of code using LOCALES.lookup_with_args):
The Example Code from the README:
use std::collections::HashMap;
use unic_langid::{LanguageIdentifier, langid};
use fluent_templates::{Loader, static_loader};
const US_ENGLISH: LanguageIdentifier = langid!("en-US");
const FRENCH: LanguageIdentifier = langid!("fr");
const GERMAN: LanguageIdentifier = langid!("de");
static_loader! {
static LOCALES = {
locales: "./tests/locales",
fallback_language: "en-US",
// Removes unicode isolating marks around arguments, you typically
// should only set to false when testing.
customise: |bundle| bundle.set_use_isolating(false),
};
}
fn main() {
assert_eq!("Hello World!", LOCALES.lookup(&US_ENGLISH, "hello-world"));
assert_eq!("Bonjour le monde!", LOCALES.lookup(&FRENCH, "hello-world"));
assert_eq!("Hallo Welt!", LOCALES.lookup(&GERMAN, "hello-world"));
let args = {
let mut map = HashMap::new();
map.insert(String::from("name"), "Alice".into());
map
};
assert_eq!("Hello Alice!", LOCALES.lookup_with_args(&US_ENGLISH, "greeting", &args));
assert_eq!("Bonjour Alice!", LOCALES.lookup_with_args(&FRENCH, "greeting", &args));
assert_eq!("Hallo Alice!", LOCALES.lookup_with_args(&GERMAN, "greeting", &args));
}
The Error:
error[E0308]: mismatched types
--> src/main.rs:31:82
|
31 | assert_eq!("Hello Alice!", LOCALES.lookup_with_args(&US_ENGLISH, "greeting", &args));
| ---------------- ^^^^^ expected `&HashMap<Cow<'_, str>, FluentValue<'_>>`, found `&HashMap<String, _>`
| |
| arguments to this method are incorrect
|
= note: expected reference `&HashMap<Cow<'static, str>, FluentValue<'_>>`
found reference `&HashMap<std::string::String, _>`
The error itself is straightforward in that LOCALES.lookup_with_args is expecting to receive a &HashMap<Cow<'_, str>, FluentValue<'_>> or something that derefs to it. However, I'm not sure what that is as I have not been using this crate for that long.