We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6a57559 commit 7bc457dCopy full SHA for 7bc457d
library/std/src/thread/spawnhook.rs
@@ -114,12 +114,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
114
snapshot
115
});
116
// Iterate over the hooks, run them, and collect the results in a vector.
117
- let mut next: &Option<Arc<SpawnHook>> = &hooks.first;
118
- let mut to_run = Vec::new();
119
- while let Some(hook) = next {
120
- to_run.push((hook.hook)(thread));
121
- next = &hook.next;
122
- }
+ let to_run: Vec<_> = std::iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
+ .map(|hook| (hook.hook)(thread))
+ .collect();
123
// Pass on the snapshot of the hooks and the results to the new thread,
124
// which will then run SpawnHookResults::run().
125
ChildSpawnHooks { hooks, to_run }
0 commit comments