orx-fixed-vec

A fixed vector, FixedVec, is a vector with a strict predetermined capacity (see SplitVec for dynamic capacity version).

It provides the following features:

Pinned elements

```rust use orxfixedvec::prelude::*;

let mut vec = FixedVec::new(100);

// push the first element vec.push(42usize); assert_eq!(vec, &[42]);

// let's get a pointer to the first element let addr42 = &vec[0] as *const usize;

// let's push 99 new elements for i in 1..100 { vec.push(i); }

for i in 0..100 { assert_eq!(if i == 0 { 42 } else { i }, vec[i]); }

// the memory location of the first element remains intact assert_eq!(addr42, &vec[0] as *const usize);

// we can safely (using unsafe!) dereference it and read the correct value assert_eq!(unsafe { *addr42 }, 42);

// the next push when vec.is_full() panics! // vec.push(0); ```

Vector with self referencing elements

FixedVec is not meant to be a replacement for std::vec::Vec.

However, it is useful and convenient in defining data structures, child structures of which hold references to each other. This is a very common and useful property for trees, graphs, etc. SplitVec allows to store children of such structures in a vector with the following features:

FixedVec helps this goal as follows: