[][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);
assert!(array[1] == 4);

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::with_label function:

struct MyLabel {
    pub even: usize,
    pub odd: usize,
}

let mut array = HeapArray::with_label(
    MyLabel { even: 0, odd: 0 },
    100,
    |label, index| {
        if index % 2 == 0 {
            label.even += 1;
            index
        } else {
            label.odd += 1;
            index
        }
    });

Modules

alloc_utils

Contains pointer math and allocation utilities.

fat_array_ptr

Contains definition of FatPtrArray, an array whose pointer is 2 words.

memory_block

Memory blocks that can hold arbitrary data on the heap. Used to represent the data that all the other types point to.

naive_rc

This module contains naively reference counted arrays, both as atomic and regular versions; i.e. if you're not careful, you could make a cycle that never gets deallocated.

thin_array_ptr

Contains definition of ThinPtrArray, an array whose pointer is 1 word.

Structs

HeapArray

Heap-allocated array, with array size stored with the pointer to the memory.

Traits

Array

Statically-sized array stored in the heap.

ArrayRef

A reference to an array, whose clone points to the same data.

AtomicArrayRef

Atomically modified array reference. Guarrantees that all operations on the array reference are atomic (i.e. all changes to the internal array pointer).

BaseArrayRef

A basic reference to a heap-allocated array. Should be paired with exactly one of either heaparray::UnsafeArrayRef or heaparray::ArrayRef.

Container

Trait for a simple container.

CopyMap

Trait for a container indexed by a value that implements Copy and Eq.

DefaultLabelledArray

Trait for a labelled array with a default value.

LabelledArray

Array with an optional label struct stored next to the data.

MakeArray

An array of arbitrary (sized) values that can be safely initialized.

UnsafeArrayRef

A reference to a heap-allocated array whose safe API guarrantees it to always be non-null.