Expand description
VecCell
is a Vec
with interior mutability and dynamically checked borrow rules.
VecCell
allows to take disjoint mutable borrows to its elements.
Example
use vec_cell::VecCell;
let vec_cell: VecCell<i32> = VecCell::new();
vec_cell.push(0);
vec_cell.push(1);
vec_cell.push(2);
{
assert_eq!(*vec_cell.borrow(0), 0);
assert_eq!(*vec_cell.borrow(1), 1);
assert_eq!(*vec_cell.borrow(2), 2);
}
{
let borrow_mut1 = &mut *vec_cell.borrow_mut(1);
let borrow_mut2 = &mut *vec_cell.borrow_mut(2);
*borrow_mut1 = 10;
*borrow_mut2 = 15;
}
assert_eq!(vec_cell.pop(), 15);
assert_eq!(vec_cell.pop(), 10);
assert_eq!(vec_cell.pop(), 0);
Structs
- A wrapper type for a immutably borrowed element from a
VecCell<T>
. - A wrapper type for a mutably borrowed element from a
VecCell<T>
. - A
Vec
with interior mutability and dynamically checked borrow rules when interacting with its elements.
Enums
- An error which may occure after calling
VecCell::try_borrow
orVecCell::try_borrow_mut
.