1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! 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.
extern crate containers_rs as containers;
/// Array with an optional label struct stored next to the data.
/// Heap-allocated array.
///
/// ## Examples
///
/// Creating an array:
/// ```rust
/// use heaparray::*;
/// let len = 10;
/// let array = HeapArray::new(len, |idx| idx + 3);
/// ```
///
/// Indexing works as you would expect:
/// ```rust
/// # use heaparray::*;
/// # let mut array = HeapArray::new(10, |idx| idx + 3);
/// array[3] = 2;
/// assert!(array[3] == 2);
/// ```
///
/// Notably, you can take ownership of objects back from the container:
///
/// ```rust
/// # use heaparray::*;
/// 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:
///
/// ```rust
/// # use heaparray::*;
/// 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
/// }
/// });
/// ```
pub use FatPtrArray as HeapArray;
pub use *;
pub use *;
pub use *;