I'm trying to use Rayon to initiate a series of top level threads to call a simulation function recursively. The code works when using channel send & receive so it is multi-threading compatible, but it fails to compile with par_iter()
.
fn simulate(initial_board: &Board, player: Player, level: u32, start: bool) -> Option<AMove> {
...
#[inline(always)]
fn evaluate_move(previous: Option<AMove>, new_move: &AMove, new_score: i32, player: Player) -> AMove {
...
}
...
let accumlator = |previous: Option<AMove>, a_move: &Option<AMove>| if let Some(AMove { board: ref a_board, .. }) = *a_move {
...
} else {
previous
};
if start && !winning {
the_move = moves.par_iter().fold(the_move, accumlator);
} else {
the_move = moves.iter().fold(the_move, accumlator);
}
the_move
}
I get a compiler error on the line with par_iter() and I'm lost on how to fix these.
error[E0277]: the trait bound `std::option::Option<AMove>: std::ops::Fn<()>` is not satisfied
--> src/main.rs:271:37
|
271 | the_move = moves.par_iter().fold(the_move, accumlator);
| ^^^^ the trait `std::ops::Fn<()>` is not implemented for `std::option::Option<AMove>`
error[E0277]: the trait bound `std::option::Option<AMove>: std::ops::FnOnce<()>` is not satisfied
--> src/main.rs:271:37
|
271 | the_move = moves.par_iter().fold(the_move, accumlator);
| ^^^^ the trait `std::ops::FnOnce<()>` is not implemented for `std::option::Option<AMove>`
error[E0308]: mismatched types
--> src/main.rs:271:20
|
271 | the_move = moves.par_iter().fold(the_move, accumlator);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::option::Option`, found struct `rayon::iter::Fold`
|
= note: expected type `std::option::Option<_>`
found type `rayon::iter::Fold<rayon::slice::Iter<'_, std::option::Option<AMove>>, std::option::Option<_>, [closure@src/main.rs:224:22: 240:6 winning:_, level:_, player:_]>`