Just avoid using iterators and you'll be fine. If you're worried about the cost of bounds checking then you probably need to rethink your algorithm, but will probably benefit from a change of data structures. Vectors of vectors are terrible for the cache and tend to perform poorly relative to a dense array.

Edit: by dense array, I mean a data structure where all the data is stored continuously, like a Fortran 2d array, or a bumpy array, or an ndarray in rust. Or just use a single Vec and use arithmetic to index it.

Does Rust have runtime determined non-growable arrays?

For example auto matrix = uninitializedArray!(ulong[][])(a.length + 1, b.length + 1); will yield me an unitialized 2D array of a.length + 1 rows and b.length + 1 columns. Of course, the lengths of a and b aren't known in compile time.

Yes, non-growable runtime determined arrays are known as Box<[T]>. You can't have 2d arrays without an allocation per sub-array that way directly, but you can do that yourself.

I assume that is due to the multiplication inside the indexing operation, which has to multiply with a variable number instead of a compile-time constant? There isn't really much you can do about that if you want the size to be runtime determined.