Crates.io | fixed_vec |
lib.rs | fixed_vec |
version | 0.1.0 |
source | src |
created_at | 2020-07-30 10:58:26.368266 |
updated_at | 2020-07-30 10:58:26.368266 |
description | Ghosts of Departed Proofs for checking valid indices of Vec's once |
homepage | https://github.com/Torrencem/fixed_vec |
repository | https://github.com/Torrencem/fixed_vec |
max_upload_size | |
id | 271239 |
size | 36,945 |
Bounds check indices only once, instead of over and over if the indices will be re-used:
use fixed_vec::{name, FixedVec};
let v = vec![0u32; 10];
let v = name!(v);
let mut v = FixedVec::fix(v);
// Perform the two index checks here:
let index_a = v.check_index(...).unwrap();
let index_b = v.check_index(...).unwrap();
for _ in 0..100 {
// These do *not* perform bounds checks!
// At compile time, v and index_a must match
*v.get_mut(index_a) += 5;
*v.get_mut(index_b) += 10;
}
let v = v.unfix();
// continue using v...
See the concept post for more information.