What is the most efficient way to get access to &mut [u8]
? Right now I'm borrowing from a Vec but it would be easier to just allocate the buffer more directly.
The best I can do right now is to preallocate a vector then push out its length but there is no way this is idiomatic.
let mut points_buf : Vec<u8> = Vec::with_capacity(points.len() * point::POINT_SIZE);
for _ in (0..points_buf.capacity()) {
points_buf.push(0);
}
file.read(&mut points_buf[..]).unwrap();
You could just create the vec with a given size directly:
Or use iterators: