[−][src]Struct arae::CurVec
A heap-allocated, fixed-size, array of values in contiguous memory designed
for efficient access via Cursor
s.
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>
orBox<[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]
F: FnMut() -> T,
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]
F: FnMut() -> Result<T, E>,
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]
fn len(&self) -> usize
[src]
fn head(&self) -> Cursor<T>
[src]
fn tail(&self) -> Cursor<T>
[src]
fn at(&self, offset: usize) -> Option<Cursor<T>>
[src]
impl<T: Clone> Clone for CurVec<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[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]
L: PartialEq<R>,
impl<T> Sequence<T> for CurVec<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> CursedExt<U> for T where
T: Cursed<U>,
[src]
T: Cursed<U>,
fn get(&self, cursor: Cursor<T>) -> &T
[src]
fn get_mut(&mut self, cursor: Cursor<T>) -> &mut T
[src]
fn is_head(&self, cursor: Cursor<T>) -> bool where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
fn is_tail(&self, cursor: Cursor<T>) -> bool where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
fn offset(&self, cursor: Cursor<T>) -> usize where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
fn wrapping_next(&self, cursor: Cursor<T>) -> Cursor<T> where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
fn wrapping_prev(&self, cursor: Cursor<T>) -> Cursor<T> where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
ⓘImportant traits for Iter<'a, C, T>fn iter(&self) -> Iter<Self, T> where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
ⓘImportant traits for Iter<'a, C, T>fn iter_at(&self, cursor: Cursor<T>) -> Iter<Self, T> where
Self: Sequence<T>,
[src]
Self: Sequence<T>,
ⓘImportant traits for WrappingIter<'a, C, T>fn wrapping_iter(&self) -> WrappingIter<Self, T> where
Self: Bounded<T>,
[src]
Self: Bounded<T>,
ⓘImportant traits for WrappingIter<'a, C, T>fn wrapping_iter_at(&self, cursor: Cursor<T>) -> WrappingIter<Self, T> where
Self: Sequence<T>,
[src]
Self: Sequence<T>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,