[][src]Struct heaparray::FatPtrArray

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::*;
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::new_labelled function:

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

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

Methods

impl<'a, E> FatPtrArray<'a, E>[src]

pub fn new<F>(len: usize, func: F) -> Self where
    F: FnMut(usize) -> E, 
[src]

Create a new array, with values initialized using a provided function.

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

pub fn new_labelled<F>(label: L, len: usize, func: F) -> Self where
    F: FnMut(&mut L, usize) -> E, 
[src]

Create a new array, with values initialized using a provided function, and label initialized to a provided value.

pub unsafe fn new_labelled_unsafe(label: L, len: usize) -> Self[src]

Create a new array, without initializing the values in it.

pub unsafe fn unchecked_access(&'a self, idx: usize) -> &'a mut E[src]

Unsafe access to an element at an index in the array.

impl<'a, E> FatPtrArray<'a, E> where
    E: Default
[src]

pub fn new_default(len: usize) -> Self[src]

Get a new array, initialized to default values.

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

pub fn new_default_labelled(label: L, len: usize) -> Self[src]

Get a new array, initialized to default values.

Trait Implementations

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

fn get_label(&self) -> &L[src]

Get a reference to the label of the array.

fn get_label_mut(&mut self) -> &mut L[src]

Get a mutable reference to the label of the array.

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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<usize, E, (usize, E)> for FatPtrArray<'a, E, L>[src]

impl<'a, E, L> Array<E> for FatPtrArray<'a, E, L>[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]