I am trying to extract two 16 byte values from the front of a large buffer into 2 16 byte smaller buffers.
I wrote a simple memcpy_safe()
function:
fn memcpy_safe(dest: &mut [u8], src: &[u8]) {
let src_len = src.len();
let dest_len = dest.len();
if(src_len != dest_len) {
println!("memcpy_safe found src and dest do not have the same length, truncating ({}, {})", src_len, dest_len);
}
for i in 0..dest_len {
if i < src_len {
dest[i] = src[i];
} else {
break;
}
}
}
and I would like to use this to do the copy, but pass the starting location of each of the 16 byte values to the parameter src
.
This is easily possible in C using pointer arithmetic, but I was wondering if a similar thing is possible in Rust. If not, what is the standard way to do something like this?