Struct vector_array::vec::VecArray

source ·
pub struct VecArray<T, const CAP: usize> { /* private fields */ }
Expand description

A Vec but entirely on the stack.

Example:

use vec_array::vec::VecArray;

let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);

Implementations§

source§

impl<T, const CAP: usize> VecArray<T, CAP>

source

pub fn new() -> Self

Creates a new VecArray.

Example:
use vec_array::vec::VecArray;

let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);
Safety:

There may be problems if you try to index in to parts of the array which are no yet initialized but this is nearly impossible.

source

pub fn push(&mut self, value: T) -> Result<(), ArrTooSmall>

Pushes an element.

Example:
use vec_array::vec::VecArray;

let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec[0], 9);
source

pub fn pop(&mut self) -> Option<T>

Removes the last element

Example:
use vec_array::vec::VecArray;

let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
assert_eq!(vec.pop(), Some(9));
Safety:

Returns memory which will realistically wont be used anymore

source

pub fn remove(&mut self, index: usize) -> T

Removes an element.

Panics:

If index is greater than or equal to length

Example:
use vec_array::vec::VecArray;
let mut vec: VecArray<_, 10> = VecArray::new();
vec.push(9).unwrap();
vec.remove(0);
assert!(vec.is_empty());
Safety:

Copied from Vec source code

source

pub fn get(&self, index: usize) -> Option<&T>

source

pub fn truncate(&mut self, len: usize)

source

pub fn as_mut_ptr(&mut self) -> *mut T

source

pub fn as_ptr(&self) -> *const T

source

pub fn get_arr(self) -> [T; CAP]

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

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

source

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

source

pub fn clear(&mut self)

source

pub fn capacity(&self) -> usize

Trait Implementations§

source§

impl<T: Clone, const CAP: usize> Clone for VecArray<T, CAP>

source§

fn clone(&self) -> VecArray<T, CAP>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T, const CAP: usize> Debug for VecArray<T, CAP>where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, const CAP: usize> Default for VecArray<T, CAP>

Does the same as ::new

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T, const CAP: usize> From<Vec<T, Global>> for VecArray<T, CAP>

source§

fn from(value: Vec<T>) -> Self

Panics:

If inputs length is greater than CAP

source§

impl<T, const CAP: usize> From<VecArray<T, CAP>> for Vec<T>

source§

fn from(val: VecArray<T, CAP>) -> Self

Converts to this type from the input type.
source§

impl<T, const CAP: usize> Index<usize> for VecArray<T, CAP>

source§

fn index(&self, index: usize) -> &Self::Output

Panics:

If index is greater than or equal to length

Use .get instead

§

type Output = T

The returned type after indexing.
source§

impl<T, const CAP: usize> IntoIterator for VecArray<T, CAP>

§

type Item = T

The type of the elements being iterated over.
§

type IntoIter = IntoIter<<VecArray<T, CAP> as IntoIterator>::Item, Global>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T, const CAP: usize> PartialEq<VecArray<T, CAP>> for VecArray<T, CAP>where T: PartialEq,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T, const CAP: usize> RefUnwindSafe for VecArray<T, CAP>where T: RefUnwindSafe,

§

impl<T, const CAP: usize> Send for VecArray<T, CAP>where T: Send,

§

impl<T, const CAP: usize> Sync for VecArray<T, CAP>where T: Sync,

§

impl<T, const CAP: usize> Unpin for VecArray<T, CAP>where T: Unpin,

§

impl<T, const CAP: usize> UnwindSafe for VecArray<T, CAP>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.