projectfluent / fluent-rs

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

intl_memoizer::IntlLangMemoizer cannot be sent to other threads. #236

Closed edfloreshz closed 2 years ago

edfloreshz commented 2 years ago

Hi, I'm trying to send a structure that includes intl_memoizer::IntlLangMemoizer, the property map with type RefCell<type_map::TypeMap> doesn't have Send + 'static implemented, is that by design or can it be changed?

Details:

error[E0277]: `RefCell<type_map::TypeMap>` cannot be shared between threads safely
   --> psst-gui/src/ui/theme.rs:147:5
    |
147 |     std::thread::spawn(move || {
    |     ^^^^^^^^^^^^^^^^^^ `RefCell<type_map::TypeMap>` cannot be shared between threads safely
    | 
   ::: /home/eduardo/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:624:8
    |
624 |     F: Send + 'static,
    |        ---- required by this bound in `spawn`
    |
    = help: within `fluent_bundle::bundle::FluentBundle<std::sync::Arc<fluent_bundle::resource::FluentResource>, intl_memoizer::IntlLangMemoizer>`, the trait `Sync` is not implemented for `RefCell<type_map::TypeMap>`
    = note: required because it appears within the type `intl_memoizer::IntlLangMemoizer`
    = note: required because it appears within the type `fluent_bundle::bundle::FluentBundle<std::sync::Arc<fluent_bundle::resource::FluentResource>, intl_memoizer::IntlLangMemoizer>`
    = note: required because of the requirements on the impl of `Sync` for `std::ptr::Unique<fluent_bundle::bundle::FluentBundle<std::sync::Arc<fluent_bundle::resource::FluentResource>, intl_memoizer::IntlLangMemoizer>>`
    = note: required because it appears within the type `alloc::raw_vec::RawVec<fluent_bundle::bundle::FluentBundle<std::sync::Arc<fluent_bundle::resource::FluentResource>, intl_memoizer::IntlLangMemoizer>>`
    = note: required because it appears within the type `Vec<fluent_bundle::bundle::FluentBundle<std::sync::Arc<fluent_bundle::resource::FluentResource>, intl_memoizer::IntlLangMemoizer>>`
    = note: required because it appears within the type `druid::localization::BundleStack`
    = note: required because it appears within the type `druid::localization::L10nManager`
    = note: required because of the requirements on the impl of `Sync` for `std::sync::Arc<druid::localization::L10nManager>`
    = note: required because it appears within the type `std::option::Option<std::sync::Arc<druid::localization::L10nManager>>`
    = note: required because it appears within the type `druid::env::EnvImpl`
    = note: required because of the requirements on the impl of `Send` for `std::sync::Arc<druid::env::EnvImpl>`
    = note: required because it appears within the type `druid::Env`
    = note: required because of the requirements on the impl of `Send` for `&mut druid::Env`
    = note: required because it appears within the type `[closure@psst-gui/src/ui/theme.rs:147:24: 159:6]
zbraniecki commented 2 years ago

Please, consult https://docs.rs/fluent-bundle/0.15.1/fluent_bundle/bundle/struct.FluentBundle.html#concurrency

edfloreshz commented 2 years ago

Thanks! This helps, closing :)