In JavaScript, there is an operator called the spread operator that allows you to combine arrays very concisely.
let x = [3, 4];
let y = [5, ...x]; // y is [5, 3, 4]
Is there a way to do something like this in Rust?
If you just need y
to be iterable, you can do:
let x = [3,4];
let y = [5].iter().chain(&x);
If you need it to be indexable, then you'll want to collect it into a vector.
let y: Vec<_> = [5].iter().chain(&x).map(|&x|x).collect();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With