0.1.0 |
|
---|
#51 in #indices
21KB
344 代码行
fixed_vec
仅对索引执行边界检查一次,而不是在索引将被重用时反复检查
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...
有关更多信息,请参阅概念帖子。
依赖项
~1.5MB
~35K SLoC