News for hackers. Stuff that matters.
Re:Everything I wish I knew when learning C by brundolf on Monday November 28, 2022 @12:59PM (#33776979)
Ironically, Rust does allow you to implicitly copy an array (or arbitrary struct), as long as it reduces to a memcpy
Re:Everything I wish I knew when learning C by tialaramex on Monday November 28, 2022 @06:33PM (#33781440)
Specifically arrays [T; N] are Copy if precisely T is Copy. So, an array of 32-bit unsigned integers [u32; N] can be copied, and so can an array of immutable string references like ["Hacker", "News", "Web", "Site"] but an array of mutable Strings cannot.

The array of mutable Strings can be memcpy'd and there are situations where that's actually what Rust will do, but because Strings aren't Copy, Rust won't let you keep both - if it did this would introduce mutable aliasing and so ruin the language's safety promise.