use reusable_memory::ReusableMemory;
let mut memory: ReusableMemory<u8> = ReusableMemory::new();
{
let mut borrowed_memory = memory.borrow_mut_as::<usize>(std::num::NonZeroUsize::new(3).unwrap());
borrowed_memory.push(1).unwrap();
borrowed_memory.push(2).unwrap();
borrowed_memory.push(std::usize::MAX).unwrap();
assert_eq!(borrowed_memory.as_slice(), &[1, 2, std::usize::MAX]);
assert_eq!(borrowed_memory.pop(), Some(std::usize::MAX));
assert_eq!(borrowed_memory.drain(..).collect::<Vec<usize>>().as_slice(), &[1, 2]);
assert_eq!(borrowed_memory.pop(), None);
}
{
let (mut borrow_t, mut borrow_u) = memory.borrow_mut_two_as::<usize, u8>(
[
std::num::NonZeroUsize::new(1).unwrap(),
std::num::NonZeroUsize::new(2).unwrap()
]
);
borrow_t.push(0usize).unwrap();
borrow_u.push(1u8).unwrap();
borrow_u.push(2u8).unwrap();
assert_eq!(borrow_t.as_slice(), &[0usize]);
assert_eq!(borrow_u.as_slice(), &[1u8, 2u8]);
}