Hi! I've written a draft of A Guide to Contiguous Data in Rust, an opinionated guide that tries to help programmers choose the best way to store contiguous data in Rust. I would love to hear if anyone has error corrections or other suggested improvements!
Some solutions can be used with
const, where the data will live in the data segment of the binary (I think??),
const is for constant evaluation (reference)
Whereas an array with type
[T; 4]stores exactly 4 elements, a
SmallVec[T; 4]can store more than 4 elements, but only the first 4 elements will be stored on the stack.
That sounds like the first 4 elements would be on the stack and the remaining ones on the heap.
If the data fits the inline capacity, it is stored on the stack, otherwise it is stored on the heap.
A honourable mention would be the
ndarray crate for using n-dimensional arrays.
It is possible to do something like:
let data = vec![vec![property]]; let element = data[x][y];
but since the first vector is just a series of references to the inner vector, this is a big noob trap and can be quite slow if you have to do a lot of reads and writes.