projectfluent / fluent-rs

Rust implementation of Project Fluent
https://projectfluent.org
Apache License 2.0
1.08k stars 97 forks source link

Concurrent FluentBundle not accessible #238

Closed FKanzler closed 5 months ago

FKanzler commented 3 years ago

Hello,

unfortunately I am not able to figure out how to access the concurrent specialization of FluentBundle.

In the documentation it says:

Concurrency


As you may have noticed, fluent_bundle::FluentBundle is a specialization of fluent_bundle::bundle::FluentBundle which works with an IntlLangMemoizer over RefCell. In scenarios where the memoizer must work concurrently, there’s an implementation of IntlLangMemoizer that uses Mutex and there’s FluentBundle::new_concurrent which works with that.

Simplified code:

use fluent_bundle::{FluentResource, FluentBundle}; //version: 0.15.1

let mut bundle = FluentBundle::new_concurrent(vec![langid!("en-US")]);

Compiler error:

error[E0599]: no function or associated item named `new_concurrent` found for struct `FluentBundle<_, intl_memoizer::IntlLangMemoizer>` in the current scope
   --> libs\translate\src\lib.rs:139:52
    |
139 |                     let mut bundle = FluentBundle::new_concurrent(vec![langid!("en-US")]);
    |                                                    ^^^^^^^^^^^^^^ function or associated item not found in `FluentBundle<_, intl_memoizer::IntlLangMemoizer>`

error: aborting due to previous error

Is there something I'm missing here? How could this be made to work?

MichaelBradetLegris commented 2 years ago

I had the same issue. A few things here.

First of all, for some reason, the method "new_concurrent" is inside of "fluent_bundle::bundle::FluentBundle", but not "fluent_bundle::FluentBundle". This should probably be updated.

Also, the IntlLangMemoizer is not exported from fluent_bundle either.

I downloaded the repo and added it as a local dependency, then inside of fluent_bundle/src/concurrent.rs, I switched the line:

use intl_memoizer::{concurrent::IntlLangMemoizer, Memoizable};

for

pub use intl_memoizer::{concurrent::IntlLangMemoizer, Memoizable};.

It works now.

This should probably be updated in the main repo.

I haven't looked into it too much, but it seems like "fluent-templates" might be using new_concurrent under the hood, and the best practice would be to use that. Not too sure about this. Might be worth a look.

gregtatum commented 1 year ago

The work here is to re-export the new_concurrent as suggested above. The IntlLangMemoizer is covered by #256.

adriantombu commented 1 year ago

@gregtatum From what I understand the problem comes from here where we redefine FluentBundle as

pub type FluentBundle<R> = bundle::FluentBundle<R, intl_memoizer::IntlLangMemoizer>

thus prohibiting any use of the new_concurrent function with a use fluent_bundle::{FluentBundle} import.


A simple solution can be to create the following type

pub type FluentBundleConcurrent<R> = concurrent::FluentBundle<R, concurrent::IntlLangMemoizer>;

to allow use fluent_bundle::{FluentBundleConcurrent}. What are your thoughts on this?

alerque commented 5 months ago

As far as I understand, this is and was fixed already. There is a comment in #300 about a regression, but looking at the code right now I don't see it. You should be able to use concurrent::FluentBundle for your type and FluentBundle::new_concurrent() as a constructor.

If I'm missing something and this is not actually viable, please by all means do comment back here and I'll re-open and re-evaluate what is going on.