-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error[E0277]: (dyn Any + 'static)
cannot be sent between threads safely
#299
Comments
Ah, good call. It's not very ergonomic now, you need to do: let bundle = bundle::FluentBundle<_, intl_memoizer::concurrent::IntlMemoizer>; |
Thank you, it works perfectly now ! |
For those who were also wondering how to do it: // an example of a basic fluent implementation with a HashMap to store languages (works with threads!)
// Don't forget to add the necessary dependencies to your Cargo.toml
use std::collections::HashMap;
use fluent::{ FluentResource, bundle::FluentBundle };
use unic_langid::{self, LanguageIdentifier, langid};
use intl_memoizer;
// Very important !!!!
type TranslationType = FluentBundle<FluentResource, intl_memoizer::concurrent::IntlLangMemoizer>;
fn load() -> HashMap<LanguageIdentifier, TranslationType> {
let mut langs: HashMap<LanguageIdentifier, TranslationType> = HashMap::new();
{
let ftl_string = include_str!("../assets/languages/fr.ftl"); // you can use a &str or read a file instead of include_str !
let res = FluentResource::try_new(ftl_string.to_string()).expect("Failed to parse an FTL string.");
let lang = langid!("fr-FR");
let mut bundle = FluentBundle::new_concurrent(vec![lang.clone()]);
bundle.add_resource(res).expect("Failed to add FTL resources to the bundle.");
langs.insert(lang, bundle);
}
langs
} It would be nice if we could find a better documentation on how to do this 😀 |
Would appreciate PR! Maybe even add type alias in |
Is there a way to achieve this while using the fluent-fallback crate ? When using this crate, a let bundles = Localization::with_env(
vec!["back.ftl".into(), "common.ftl".into()],
true,
vec![langid!("fr-FR"), langid!("en-US")],
ResourceManager::new("../translations/{locale}/{res_id}".to_string()),
).bundles(); Then, I get |
You would want to introduce a |
Well, I understand why to use Then I don't know at all how could I introduce a (Sorry, I'm pretty new to Rust) |
You would need to create an equivalent of You would need to write it all, there is no such solution yet. |
Why would it be parameterized on |
hmm, maybe you're right. I don't have the complete mental model in my mind now. Maybe you need to adjust ResourceManager? And that may require a Localization that works with concurrent ResourceManager that produces concurrent FluentBundle. |
I think the file But I don't have the knowledge in Rust to do this so I'll wait for someone to fix the issue. |
Hi, I know this error is an issue that has been closed, but I don't understand HOW to access the "new_concurrent" method.
When I use this code:
It doesn't give any error (in that part, I use threads so this part broke my whole project).
But, when I try to use the
FluentBundle::new_concurrent
method instead ofFluentBundle::new
, it says that this function doesn't exist, and I can't find anything about it in the documentation.How can we access to this method ?
The text was updated successfully, but these errors were encountered: