I have a piece of code ( a music decoder ) that returns a tuple with values for the left and the right channel. At the moment the code does the following
let (left,right) = next_sample();
sample[0] = left;
sample[1] = right;
but it feels like I should be able to do something along the lines of
(sample[0],sample[1]) = next_sample();
Is there a way to achieve this or is this just not supported in Rust (yet)
If you change next_sample to return a [T; 2] instead of a tuple, you can do sample.copy_from_slice(&next_sample()) if sample is a type that derefs to a slice and T is Copy. Or use swap_with_slice in a similar manner if it’s not Copy. Just an option to consider ...