Skip to content

Send+Sync bound expectations on some types #361

@ten3roberts

Description

@ten3roberts

Worley noise (and some other functions) contain custom Rc<Fn> distance functions.

Usage of Rc makes these types non-Send, which makes it difficult to use in many ECS implementations

Would it be possible to change the type to Arc or possibly introduce a generic with a default value to get around these limitations?

error[E0277]: `Rc<(dyn for<'a, 'b> std::ops::Fn(&'a [f64], &'b [f64]) -> f64 + 'static)>` cannot be shared between threads safely
   --> shared/src/entities/enemy_controller.rs:150:17
    |
150 |     idle_state: IdleState,
    |                 ^^^^^^^^^ `Rc<(dyn for<'a, 'b> std::ops::Fn(&'a [f64], &'b [f64]) -> f64 + 'static)>` cannot be shared between threads safely
    |
    = help: within `IdleState`, the trait `Sync` is not implemented for `Rc<(dyn for<'a, 'b> std::ops::Fn(&'a [f64], &'b [f64]) -> f64 + 'static)>`, which is required by `IdleState: ComponentValue`
note: required because it appears within the type `Worley`
   --> /home/freja/.cargo/registry/src/index.crates.io-6f17d22bba15001f/noise-0.9.0/src/noise_fns/generators/worley.rs:11:12
    |
11  | pub struct Worley {

From looking at the code, a non-Send distance function is not required, as the provided distance functions are purely "math" and thus could be send.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions