#1089·rayon

`ParallelExtend` for tuples of references

Author: xosmigCreated Sep 6, 2023Updated Aug 10, 2026

ParallelExtend implemented for tuples allows extending multiple collections from one ParallelIterator, which is really useful. This code works as expected:

rust
let vec1 = vec![1., 2., 3.];
let vec2 = vec!["1".to_string(), "2".to_string(), "3".to_string()];

let input = vec![4, 5, 6];

let mut vecs = (vec1, vec2);
vecs.par_extend(input.into_par_iter().map(|i| (i as f64, i.to_string())));

assert_eq!(&vecs.0, &vec![1., 2., 3., 4., 5., 6.]);
assert_eq!(&vecs.1, &vec!["1", "2", "3", "4", "5", "6"]);

However, the way it is implemented now, the two collections actually have to be stored as a tuple. This code doesn't compile:

rust
let mut vec1 = vec![1., 2., 3.];
let mut vec2 = vec!["1".to_string(), "2".to_string(), "3".to_string()];

let input = vec![4, 5, 6];

// Error: method not found in `(&mut Vec<{float}>, &mut Vec<String>)`
(&mut vec1, &mut vec2).par_extend(input.into_par_iter().map(|i| (i as f64, i.to_string())));

assert_eq!(&vec1, &vec![1., 2., 3., 4., 5., 6.]);
assert_eq!(&vec2, &vec!["1", "2", "3", "4", "5", "6"]);

This looks like a natural use-case and I encountered it at least a couple of times while using rayon. Am I missing some other tools to implement what I want? If not, would it be possible to add support for it? Perhaps, with a slightly different API as implementing ParallelExtend for (&mut FromA, &mut FromB) would probably conflict with the original implementation for (FromA, FromB).