1 use intl_memoizer::{concurrent::IntlLangMemoizer, Memoizable};
2 use rustc_hash::FxHashMap;
3 use unic_langid::LanguageIdentifier;
5 use crate::bundle::FluentBundle;
6 use crate::memoizer::MemoizerKind;
7 use crate::types::FluentType;
9 impl<R> FluentBundle<R, IntlLangMemoizer> {
10 /// A constructor analogous to [`FluentBundle::new`] but operating
11 /// on a concurrent version of [`IntlLangMemoizer`] over [`Mutex`](std::sync::Mutex).
16 /// use fluent_bundle::bundle::FluentBundle;
17 /// use fluent_bundle::FluentResource;
18 /// use unic_langid::langid;
20 /// let langid_en = langid!("en-US");
21 /// let mut bundle: FluentBundle<FluentResource, _> =
22 /// FluentBundle::new_concurrent(vec![langid_en]);
24 pub fn new_concurrent(locales: Vec<LanguageIdentifier>) -> Self {
25 let first_locale = locales.get(0).cloned().unwrap_or_default();
29 entries: FxHashMap::default(),
30 intls: IntlLangMemoizer::new(first_locale),
38 impl MemoizerKind for IntlLangMemoizer {
39 fn new(lang: LanguageIdentifier) -> Self
46 fn with_try_get_threadsafe<I, R, U>(&self, args: I::Args, cb: U) -> Result<R, I::Error>
49 I: Memoizable + Send + Sync + 'static,
50 I::Args: Send + Sync + 'static,
53 self.with_try_get(args, cb)
56 fn stringify_value(&self, value: &dyn FluentType) -> std::borrow::Cow<'static, str> {
57 value.as_string_threadsafe(self)