[][src]Crate reusable_memory

To reuse memory, it needs to be allocated first:

use reusable_memory::ReusableMemory;

let mut memory: ReusableMemory<u8> = ReusableMemory::new();
// The memory can then be borrowed as a different type:
let mut borrowed_memory = memory.borrow_mut_as::<usize>(std::num::NonZeroUsize::new(3).unwrap());

// Now `borrowed_memory` holds a pointer to enough memory to store 3 properly-aligned `usize`s inside the memory allocated in `memory`.
borrowed_memory.push(1).unwrap();
borrowed_memory.push(2).unwrap();
borrowed_memory.push(std::usize::MAX).unwrap();

push will return an Err if the pushed value would not fit into the capacity of the borrowed memory.

The borrowed memory is automatically returned when the object is dropped, and the pushed values are dropped as well.

Modules

borrow

Structs

ReusableMemory

Reusable memory struct.