Hey everyone,
Basically, I want to fill a Vec<u8>
with data from an external source and I also don't want to pay the cost for initializing the memory.
What's the idiomatic way of accomplishing such a goal? For example, is this okay?
let mut buf = Vec::<u8>::with_capacity(1024);
let ptr = buf.as_mut_ptr();
for idx in 0..1024 {
unsafe { ptr.add(idx).write(idx * idx) };
}
unsafe { buf.set_len(1024) };
return buf;