[][src]Struct dynamic_array::array::Array

pub struct Array<T, Len: Copy + Into<usize> + TryFrom<usize>> { /* fields omitted */ }

A dynamically-allocated array of fixed size.

Example

use dynamic_array::SmallArray;

let mut arr = SmallArray::<u32>::zeroed(9);

assert!(!arr.is_empty());

// can be freely dereferenced
assert_eq!(arr[3], 0);

arr[7] = 8;

assert_eq!(arr[7], 8);

let mut arr2 = arr.clone();

assert_ne!(arr2[3],4);
arr[2] = 4;
arr2[3] = 4;
assert_eq!(arr[2],4);
assert_eq!(arr2[3],4);

// can also be freely iterated
for x in arr.iter_mut() {
    *x += 1;
}

assert_eq!(arr[2], 5);

Implementations

impl<T, Len: Copy + Into<usize> + TryFrom<usize>> Array<T, Len>[src]

pub fn zeroed(len: Len) -> Self[src]

Creates a zeroed Array with length len.

pub fn from_raw(raw: *mut T, len: Len) -> Self[src]

Constructs a new Array from a raw pointer.

After calling this function the pointer is owned by the resulting Array.

pub fn from_vec(v: Vec<T>) -> Self where
    <Len as TryFrom<usize>>::Error: Debug
[src]

Constructs a new Array from a given Vec.

Example

use dynamic_array::SmallArray;

let mut v = vec![8,9,10usize];
v.reserve(1000);

let arr = SmallArray::from_vec(v);

assert_eq!(arr.len(), 3);

pub fn into_vec(self) -> Vec<T>[src]

Constructs a Vec from Self.

Example

use dynamic_array::SmallArray;

let arr = SmallArray::<usize>::zeroed(5);

let v: Vec<usize> = arr.into_vec();

assert_eq!(v.len(), 5);
assert_eq!(v[3], 0);

pub fn len(&self) -> Len[src]

The length of the array

Example

use dynamic_array::SmallArray;
let arr = SmallArray::<()>::zeroed(42);

assert_eq!(arr.len(), 42);

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

Trait Implementations

impl<T: Clone, Len: Copy + Into<usize> + TryFrom<usize>> Clone for Array<T, Len>[src]

impl<T: Debug, Len: Copy + Into<usize> + TryFrom<usize>> Debug for Array<T, Len>[src]

impl<T, Len: Copy + Into<usize> + TryFrom<usize>> Deref for Array<T, Len>[src]

type Target = [T]

The resulting type after dereferencing.

impl<T, Len: Copy + Into<usize> + TryFrom<usize>> DerefMut for Array<T, Len>[src]

impl<T, Len: Copy + Into<usize> + TryFrom<usize>> Drop for Array<T, Len>[src]

impl<T, Len: Copy + Into<usize> + TryFrom<usize>> IntoIterator for Array<T, Len>[src]

type Item = T

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'t, T, Len: Copy + Into<usize> + TryFrom<usize>> IntoIterator for &'t Array<T, Len>[src]

type Item = &'t T

The type of the elements being iterated over.

type IntoIter = Iter<'t, T>

Which kind of iterator are we turning this into?

impl<'t, T, Len: Copy + Into<usize> + TryFrom<usize>> IntoIterator for &'t mut Array<T, Len>[src]

type Item = &'t mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'t, T>

Which kind of iterator are we turning this into?

impl<T: Send, Len: Copy + Into<usize> + TryFrom<usize>> Send for Array<T, Len>[src]

impl<T: Sync, Len: Copy + Into<usize> + TryFrom<usize>> Sync for Array<T, Len>[src]

Auto Trait Implementations

impl<T, Len> RefUnwindSafe for Array<T, Len> where
    Len: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, Len> Unpin for Array<T, Len> where
    Len: Unpin

impl<T, Len> UnwindSafe for Array<T, Len> where
    Len: UnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.