orx-fixed-vec
FixedVec
implements PinnedVec
; therefore,
- it preserves the memory locations of already pushed elements.
This feature eliminates a specific set of errors leading to undefined behavior, and hence, allows to work with a more flexible borrow checker.
Furthermore, it can be used as the underlying pinned vector of an
ImpVec
, which adds the additional feature
to push to the vector with an immutable reference.
Unlike, another pinned vector implementation SplitVec
,
FixedVec
allows operations with same complexity and speed of std::vec::Vec
.
Its drawback, on the other hand, is that:
- it has a hard limit on its capacity,
- it will panic if the caller attempts to extend the vector beyond this limit.
use *;
let fixed_capacity = 42;
let mut vec = new;
assert_eq!;
let mut initial_addresses = vec!;
for i in 0..fixed_capacity
assert_eq!;
assert_eq!;
assert!;
// addresses of already pushed elements stay intact
let final_addresses: =
.map
.collect;
assert_eq!;
// the next push when `vec.is_full()` panics!
// vec.push(42);