[][src]Struct arae::CurVec

pub struct CurVec<T> { /* fields omitted */ }

A heap-allocated, fixed-size, array of values in contiguous memory designed for efficient access via Cursors.

You can access the elements of a CurVec<T> the same way you would a Vec<T> or Box<[T]> however it's characteristics are different to what either provide. Unlike a Vec<T> which stores the data ptr, length and capacity a CurVec<T> stores the starting element ptr (head) and end element ptr (tail).

A CurVec<T>:

  • Cannot be empty.
  • Cannot contain elements of mem::size_of() == 0.
  • Cannot be resized (and does not have any notion of capacity).

Conversion

  • Converting from and into a Vec<T> or Box<[T]> is a zero-copy operation.
  • When converting from a Vec<T> excess capacity is stripped.
  • Converting from a Vec<T>, Box<[T]> or similar types will panic if their length is zero.

Example

use arae::{CurVec, CursedExt, Bounded};

// Create a new `CurVec` of length 10 with the elements
// initialized via `Default::default`.
let mut vec = CurVec::new_with_default(10);

// Create two cursors pointing the the head of the vec.
let write_cursor = vec.head();
let read_cursor = vec.head();

// Write the value `1` at the element pointed by `write_cursor`.
*vec.get_mut(write_cursor) = 1;

// Read the value at the element pointed by `read_cursor`.
assert_eq!(*vec.get(read_cursor), 1);

Methods

impl<T> CurVec<T>[src]

pub fn new_with_init<F>(len: usize, init_fn: F) -> Self where
    F: FnMut() -> T, 
[src]

Construct a new CurVec with a given length and an element initializer that cannot fail.

pub fn try_new_with_init<F, E>(len: usize, init_fn: F) -> Result<Self, E> where
    F: FnMut() -> Result<T, E>, 
[src]

Construct a new CurVec with a given length and an element initializer that may fail.

pub unsafe fn from_raw_parts(head: NonNull<T>, len: usize) -> Self[src]

Construct a new CurVec from its raw parts.

Panics

Panics if len is zero or greater than isize::max_value().

Safety

See the safety notes for Vec::from_raw_parts.

pub fn as_slice(&self) -> &[T][src]

Return a slice of the elements.

pub fn as_slice_mut(&mut self) -> &mut [T][src]

Return a mutable slice of the elements.

pub fn into_boxed_slice(self) -> Box<[T]>[src]

Consume self into a Box<[T]>.

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

Consume self into a Vec<T>.

impl<T: Default> CurVec<T>[src]

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

Construct a new CurVec with a given length with elements initialized via Default::default().

Trait Implementations

impl<T> AsMut<[T]> for CurVec<T>[src]

impl<T> AsRef<[T]> for CurVec<T>[src]

impl<T> Bounded<T> for CurVec<T>[src]

impl<T: Clone> Clone for CurVec<T>[src]

impl<T> Contiguous<T> for CurVec<T>[src]

impl<T> Cursed<T> for CurVec<T>[src]

impl<T: Debug> Debug for CurVec<T>[src]

impl<T> Drop for CurVec<T>[src]

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

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

impl<L, R> PartialEq<CurVec<R>> for CurVec<L> where
    L: PartialEq<R>, 
[src]

impl<T> Sequence<T> for CurVec<T>[src]

Auto Trait Implementations

impl<T> !Send for CurVec<T>

impl<T> !Sync for CurVec<T>

impl<T> Unpin for CurVec<T>

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, U> CursedExt<U> for T where
    T: Cursed<U>, 
[src]

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

impl<T, U> Into<U> for T where
    U: From<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.