Skip to content

Commit bc69804

Browse files
committed
fix!: new_thread_state() functions are now FnOnce across the board.
This properly communicates that they will only be called once per thread, while providing more options to the implementor.
1 parent cfd8e88 commit bc69804

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

gix-features/src/parallel/in_parallel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn build_thread() -> std::thread::Builder {
4949
pub fn in_parallel<I, S, O, R>(
5050
input: impl Iterator<Item = I> + Send,
5151
thread_limit: Option<usize>,
52-
new_thread_state: impl Fn(usize) -> S + Send + Clone,
52+
new_thread_state: impl FnOnce(usize) -> S + Send + Clone,
5353
consume: impl FnMut(I, &mut S) -> O + Send + Clone,
5454
mut reducer: R,
5555
) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>
@@ -117,7 +117,7 @@ where
117117
pub fn in_parallel_with_slice<I, S, R, E>(
118118
input: &mut [I],
119119
thread_limit: Option<usize>,
120-
new_thread_state: impl FnMut(usize) -> S + Send + Clone,
120+
new_thread_state: impl FnOnce(usize) -> S + Send + Clone,
121121
consume: impl FnMut(&mut I, &mut S, &AtomicIsize, &AtomicBool) -> Result<(), E> + Send + Clone,
122122
mut periodic: impl FnMut() -> Option<std::time::Duration> + Send,
123123
state_to_rval: impl FnOnce(S) -> R + Send + Clone,
@@ -168,7 +168,7 @@ where
168168
std::thread::Builder::new()
169169
.name(format!("gitoxide.in_parallel_with_slice.produce.{thread_id}"))
170170
.spawn_scoped(s, {
171-
let mut new_thread_state = new_thread_state.clone();
171+
let new_thread_state = new_thread_state.clone();
172172
let state_to_rval = state_to_rval.clone();
173173
let mut consume = consume.clone();
174174
let input = Input(input as *mut [I]);

gix-features/src/parallel/serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod not_parallel {
9494
pub fn in_parallel_with_slice<I, S, R, E>(
9595
input: &mut [I],
9696
_thread_limit: Option<usize>,
97-
mut new_thread_state: impl FnMut(usize) -> S + Clone,
97+
new_thread_state: impl FnOnce(usize) -> S + Clone,
9898
mut consume: impl FnMut(&mut I, &mut S, &AtomicIsize, &AtomicBool) -> Result<(), E> + Clone,
9999
mut periodic: impl FnMut() -> Option<std::time::Duration>,
100100
state_to_rval: impl FnOnce(S) -> R + Clone,
@@ -128,7 +128,7 @@ pub use not_parallel::{build_thread, in_parallel_with_slice, join, threads, Scop
128128
pub fn in_parallel<I, S, O, R>(
129129
input: impl Iterator<Item = I>,
130130
_thread_limit: Option<usize>,
131-
new_thread_state: impl Fn(usize) -> S,
131+
new_thread_state: impl FnOnce(usize) -> S,
132132
mut consume: impl FnMut(I, &mut S) -> O,
133133
mut reducer: R,
134134
) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>

0 commit comments

Comments
 (0)