Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clone an array with length bigger than 32?

Tags:

A fixed-length array of a native type (or of a type that implements the Copy trait) can be cloned in Rust up to the length of 32. That is, this compiles:

fn main() {
    let source: [i32; 32] = [0; 32]; // length 32
    let _cloned = source.clone();
}

But this doesn't:

fn main() {
    let source: [i32; 33] = [0; 33]; // length 33
    let _cloned = source.clone(); // <-- compile error
}

In fact, the trait Clone only declares a method for each generic array length, from 0 to 32.

What is an efficient and idiomatic way to clone a generic array of length, say, 33?