3 ms·
I think Steve might have forgotten (so many helper functions...), but Rust's slices have a `copy_within`[1] function for exactly this scenario: fn main() {
by Measter 2y ago
I think Steve might have forgotten (so many helper functions...), but Rust's slices have a `copy_within`[1] function for exactly this scenario:
fn main() {
let mut buf: [u8; 16] = *b"D04GOKUD09OVER90";
buf.copy_within(7..16, 0);
println!("{:?}", buf);
}
It does only support types that are trivially copyable, but it's implemented exactly you'd expect: bounds checking then memcopy handling overlap.
[1] https://doc.rust-lang.org/std/primitive.slice.html#method.copy_within https://doc.rust-lang.org/std/primitive.slice.html#method.co...
- steveklabnik 2y agoI did! Wow! Thanks :)