I want to iterate over a data source and produce more then one entry in the resulting iterator for each input value.
This is a heavily reduced example of my problem:
led_values.extend(iter.flat_map( |x: u64| [x as u16, x as u16, x as u16].into_iter() ));
That gives me:
error[E0597]: borrowed value does not live long enough --> src/main.rs:156:75 | 2 | |x: u64| [x as u16, x as u16, x as u16].into_iter() | ------------------------------ ^ temporary value dropped here while still borrowed | | | temporary value created here 3 | )); | - temporary value needs to live until here
After hours of investigations I think I’ve now understood why this happens:
into_iter is only implemented for
&[T; N] and not
[T; N] - which was completely unexpected to me!
into_iter not implemented for
How can I solve the actual problem of
mapping a single value to multiple result values?
Thanks for any hints!