[−][src]Crate heaparray
This crate holds a struct, HeapArray, that internally points to a contiguous block of memory. It also supports storing arbitrary data adjacent to the block of memory.
Examples
Creating an array:
use heaparray::*; let len = 10; let array = HeapArray::new(len, |idx| idx + 3);
Indexing works as you would expect:
array[3] = 2; assert!(array[3] == 2);
Notably, you can take ownership of objects back from the container:
let mut array = HeapArray::new(10, |_| Vec::<u8>::new()); let replacement_object = Vec::new(); let owned_object = array.insert(0, replacement_object);
but you need to give the array a replacement object to fill its slot with.
Additionally, you can customize what information should be stored alongside the elements in the array using the HeapArray::new_labelled function:
struct MyLabel { pub even: usize, pub odd: usize, } let mut array = HeapArray::new_labelled( MyLabel { even: 0, odd: 0 }, 100, |label, index| { if index % 2 == 0 { label.even += 1; index } else { label.odd += 1; index } });
Re-exports
pub use crate::fat_array_ptr::FatPtrArray as HeapArray; |
Modules
alloc | Contains pointer math and allocation utilities. |
fat_array_ptr | Contains definition of |
memory_block | Memory blocks that can be created on the heap to hold an arbitrary amount of data. |
thin_array_ptr | Contains definition of |
Traits
Array | Statically-sized array stored in the heap. |
Container | Trait for a simple container. |
CopyMap | Trait for a container indexed by a value that implements |
LabelledArray | Array with an optional label struct stored next to the data. |