Typically Vec is dynamically-sized, implying that it requires a heap.
If performance is critical, it is possible to allocate data on the stack for small arrays.

There are three approaches to do so. Note that all approaches below essentially require fixed-size data allocation since they are on the stack.

  • Use arrays []
  • Use const generics
  • Use external static-allocation libraries like arrayvec or heapless (for a Vec-like API)