0

copy_from_slice requires the source and destination slices to have the same lenght.

How can I copy from a slice smaller than its destination?

The closest I found was How do you copy between arrays of different sizes in Rust?, it lists

for (dst, src) in slice_destination.iter_mut().zip(slice_source) {
    *dst = *src
}

It worked for me. But is there an easier way?

Guerlando OCs
  • 1,886
  • 9
  • 61
  • 150
  • It would be great if you could include a more complete example. Also, if the slices are different sizes, can you create a new slice that is a subset of the longer one with the length of the smaller one, and then copy using those instead? – loganfsmyth May 25 '20 at 04:51
  • Added your answer to your duplicate ;) – Stargateur May 25 '20 at 05:04

0 Answers0