[][src]Struct heaparray::fat_array_ptr::FatPtrArray

#[repr(C)]
pub struct FatPtrArray<'a, E, L = ()> where
    Self: 'a, 
{ /* fields omitted */ }

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

Examples

Creating an array:

use heaparray::fat_array_ptr::*;
let len = 10;
let array = FatPtrArray::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 = FatPtrArray::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 FatPtrArray::with_label function:

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

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

Invariants

This struct follows the same invariants as mentioned in crate::memory_block, and does not check for pointer validity; you should use this struct in the same way you would use a raw array or slice.

Trait Implementations

impl<'a, E, L> BaseArrayRef for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> UnsafeArrayRef for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> LabelledArray<'a, E, L> for FatPtrArray<'a, E, L> where
    E: 'a, 
[src]

impl<'a, E, L> DefaultLabelledArray<'a, E, L> for FatPtrArray<'a, E, L> where
    E: 'a + Default
[src]

impl<'a, E> MakeArray<'a, E> for FatPtrArray<'a, E, ()> where
    E: 'a, 
[src]

impl<'a, E, L> Clone for FatPtrArray<'a, E, L> where
    E: Clone,
    L: Clone
[src]

impl<'a, E, L> Drop for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> Index<usize> for FatPtrArray<'a, E, L>[src]

type Output = E

The returned type after indexing.

impl<'a, E, L> IndexMut<usize> for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> Container<(usize, E)> for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> CopyMap<'a, usize, E, (usize, E), &'a E, &'a mut E> for FatPtrArray<'a, E, L> where
    E: 'a, 
[src]

impl<'a, E, L> Array<'a, E, &'a E, &'a mut E> for FatPtrArray<'a, E, L> where
    E: 'a, 
[src]

Auto Trait Implementations

impl<'a, E, L> Send for FatPtrArray<'a, E, L> where
    E: Send,
    L: Send

impl<'a, E, L> Sync for FatPtrArray<'a, E, L> where
    E: Sync,
    L: Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]