Mark Schultz-Wu
Mark Schultz-Wu

Reputation: 374

Where is Clone implemented for [u32; N]?

I have a struct that I want to implement .clone_from() for to reuse a stack allocation. The struct is relatively simple (all types in it are Copy except a [u32; N]). I could blindly just call a.clone_from(&b) on the a : [u32; N], but it is possible that the .clone_from() implementation for this type in the standard library is not good, and that this will compute let a = b.clone(), and will not reuse the stack allocation.

So, I want to look at the Clone implementation of arrays myself to make sure, but I am having difficulty finding it within the nightly docs. I have looked in:

  1. The clone doc page and clone source. I see nothing like impl <const N : usize> Clone for [T; N] in either of these places

  2. The array (primitive type) and array source, where again I see no implementation.

So where is the implementation? How can I check that calling a.clone_from(&b) will reuse my allocation?

Upvotes: 0

Views: 133

Answers (1)

HHK
HHK

Reputation: 5320

Fixed-size arrays of types that implement Copy (like u32) automatically implement Copy so they are efficiently copied bit-wise, see the array (primitive type) documentation.

Upvotes: 1

Related Questions