[][src]Struct heaparray::base::BaseArray

#[repr(transparent)]
pub struct BaseArray<E, L, P = NonNull<MemBlock<E, L>>> where
    P: BaseArrayPtr<E, L>, 
{ /* fields omitted */ }

Base array that handles converting a memory block into a constructible object.

Doesn't store length information, but contains logic necessary to handle allocation, deallocation, iteration, and slices given length. Holds the bulk of the unsafe logic in this library.

Requires the user to specify the internal structure that handles allocation and pointer math, which can be done through implementing the BaseArrayPtr trait.

Memory Leaks

This struct doesn't perform memory cleanup automatically; it must be done manually with methods drop or drop_lazy.

Methods

impl<E, L, P> BaseArray<E, L, P> where
    P: BaseArrayPtr<E, L>, 
[src]

pub unsafe fn from_ptr(ptr: P) -> Self[src]

Construct an instance of this struct from an instance of the pointer type P.

pub fn as_ptr(&self) -> &P[src]

Returns a reference to the underlying pointer of this base array.

pub fn as_ptr_mut(&mut self) -> &mut P[src]

Returns a mutable reference to the underlying pointer of this base array.

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

Doesn't initialize anything in the array. Just allocates a block of memory.

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

Doesn't initialize the elements of the array.

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

Creates a new array of size len.

Initializes all elements using the given function, and initializes the label with the provided value.

pub unsafe fn drop(&mut self, len: usize)[src]

Runs destructor code for elements and for label, then deallocates block.

Safety

Function is safe as long as the underlying array is at least length len, and the elements in the array have been initialized.

pub unsafe fn drop_lazy(&mut self, len: usize)[src]

Deallocates block without running destructor code for elements or label.

Safety

Function is safe as long as the underlying array is at least length len.

pub unsafe fn cast_into<T, Q>(self) -> BaseArray<T, L, Q> where
    Q: BaseArrayPtr<T, L>, 
[src]

Cast this array into a different array.

Doesn't alter the length information of the array at all, or perform alignment/reference checks.

pub unsafe fn cast_ref<T, Q>(&self) -> &BaseArray<T, L, Q> where
    Q: BaseArrayPtr<T, L>, 
[src]

Cast a reference to this array into a reference to a different array.

Doesn't alter the length information of the array at all, or perform alignment/reference checks.

pub unsafe fn cast_mut<T, Q>(&mut self) -> &mut BaseArray<T, L, Q> where
    Q: BaseArrayPtr<T, L>, 
[src]

Cast a mutable reference to this array into a mutable reference to a different array.

Doesn't alter the length information of the array at all, or perform alignment/reference checks.

pub fn get_ptr(&self, idx: usize) -> *const E[src]

Returns a pointer to the element at the index idx.

Safety

Pointer is safe to dereference as long as the underlying array has a length greater than idx, and the element at idx has already been initialized.

pub fn get_ptr_mut(&mut self, idx: usize) -> *mut E[src]

Returns a mutable pointer to the element at the index idx.

Safety

Pointer is safe to dereference as long as the underlying array has a length greater than idx, and the element at idx has already been initialized.

pub fn is_null(&self) -> bool[src]

Returns whether or not the internal pointer in this array is null.

pub unsafe fn get(&self, idx: usize) -> &E[src]

Returns a reference to the element at the index idx.

Safety

Safe as long as the underlying array has a length greater than idx, and the element at idx has already been initialized.

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

Returns a mutable reference to the element at the index idx.

Safety

Safe as long as the underlying array has a length greater than idx, and the element at idx has already been initialized.

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

Returns a reference to the label.

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

Returns a mutable reference to the label.

pub unsafe fn as_slice(&self, len: usize) -> &[E][src]

Returns a reference to a slice into this array.

The slice is from element 0 to len - 1 inclusive.

pub unsafe fn as_slice_mut(&mut self, len: usize) -> &mut [E][src]

Returns a mutable reference to a slice into this array.

The slice is from element 0 to len - 1 inclusive.

Important traits for BaseArrayIter<E, L, P>
pub unsafe fn into_iter(self, len: usize) -> BaseArrayIter<E, L, P>[src]

Returns an iterator into this array, consuming the array in the process.

impl<E, L, P> BaseArray<E, L, P> where
    E: Clone,
    L: Clone,
    P: BaseArrayPtr<E, L>, 
[src]

pub unsafe fn clone(&self, len: usize) -> Self[src]

Clones the elements and label of this array into a new array of the same size.

Auto Trait Implementations

impl<E, L, P = NonNull<MemBlock<E, L>>> !Send for BaseArray<E, L, P>

impl<E, L, P = NonNull<MemBlock<E, L>>> !Sync for BaseArray<E, L, P>

Blanket Implementations

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

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

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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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