Skip to content
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

Trait bounds not satisfied for ParallelIterator methods? #291

Open
OtherJohnGray opened this issue Jan 14, 2024 · 1 comment
Open

Trait bounds not satisfied for ParallelIterator methods? #291

OtherJohnGray opened this issue Jan 14, 2024 · 1 comment

Comments

@OtherJohnGray
Copy link

I'm probably doing something really silly, however, just in case this is a legitimate issue:

With latest DashMap from github:

[package]
name = "par_maps"
version = "0.1.0"
edition = "2021"

[dependencies]
rayon = "1.8.0"
#dashmap = "5.5.3"
dashmap = { git = "https://github.com/xacrimon/dashmap.git", branch = "master", features = ["inline"] }

And the following test code:

use dashmap::DashMap;

fn main() {
    // Create a new DashMap
    let map = DashMap::new();

    // Populate the map
    for i in 0..100 {
        map.insert(i, i * 2);
    }

    // Use Rayon to iterate over the map in parallel
    map.par_iter().for_each(|pair| {
        println!("Key: {}, Value: {}", *pair.key(), *pair.value());
    });
}

I get the following error:

johngray@practice ~/w/b/par_maps (master) [127]> cargo build
   Compiling par_maps v0.1.0 (/home/johngray/workspace/benchmarks/par_maps)
error[E0599]: no method named `par_iter` found for struct `DashMap` in the current scope
  --> src/main.rs:13:9
   |
13 |     map.par_iter().for_each(|pair| {
   |         ^^^^^^^^ help: there is a method with a similar name: `iter`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `par_maps` (bin "par_maps") due to 1 previous error

And if I then add a use statement for the rayon prelude:

use dashmap::DashMap;
use rayon::prelude::*;

fn main() {
    // Create a new DashMap
    let map = DashMap::new();

    // Populate the map
    for i in 0..100 {
        map.insert(i, i * 2);
    }

    // Use Rayon to iterate over the map in parallel
    map.par_iter().for_each(|pair| {
        println!("Key: {}, Value: {}", *pair.key(), *pair.value());
    });
}
    
I get the following error:

    johngray@practice ~/w/b/par_maps (master) [101]> cargo build
   Compiling par_maps v0.1.0 (/home/johngray/workspace/benchmarks/par_maps)
error[E0599]: the method `par_iter` exists for struct `DashMap<{integer}, {integer}>`, but its trait bounds were not satisfied
  --> src/main.rs:14:9
   |
14 |     map.par_iter().for_each(|pair| {
   |         ^^^^^^^^
   |
  ::: /home/johngray/.cargo/git/checkouts/dashmap-d1e8e211bd771f55/626b98d/src/lib.rs:88:1
   |
88 | pub struct DashMap<K, V, S = RandomState> {
   | ----------------------------------------- doesn't satisfy `_: IntoParallelRefIterator<'_>`
   |
   = note: the following trait bounds were not satisfied:
           `&DashMap<{integer}, {integer}>: IntoParallelIterator`
           which is required by `DashMap<{integer}, {integer}>: rayon::iter::IntoParallelRefIterator<'_>`

warning: unused import: `rayon::prelude`
 --> src/main.rs:2:5
  |
2 | use rayon::prelude::*;
  |     ^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

For more information about this error, try `rustc --explain E0599`.
warning: `par_maps` (bin "par_maps") generated 1 warning
error: could not compile `par_maps` (bin "par_maps") due to 1 previous error; 1 warning emitted

Am I doing this the wrong way, or is this an issue?

@tomkarw
Copy link
Contributor

tomkarw commented Feb 3, 2024

Have you tried with rayon feature of DashMap enabled?

dashmap = { version = "5.5.3", features = ["rayon"] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants