AnyVec

Struct AnyVec 

Source
pub struct AnyVec { /* private fields */ }
Expand description

A growable list type with dynamic typing.

It can store anything that implements the Any trait.

Implementations§

Source§

impl AnyVec

Source

pub fn new() -> Self

Constructs a new, empty AnyVec.

Source

pub fn with_capacity(capacity: usize, avg_type_size: usize) -> Self

Constructs a new, empty AnyVec with specified capacity.

Since we do not type sizes ahead, an average type size avg_type_size must be specified.

Source

pub fn capacity(&self, type_size: usize) -> usize

Returns the number of elements the vector can hold without reallocating.

Source

pub fn reserve(&mut self, additional: usize, avg_type_size: usize)

Reserves capacity for at least additional more elements.

Since we do not type sizes ahead, an average type size avg_type_size must be specified.

§Panics

Panics if the new capacity overflows usize.

Source

pub fn reserve_exact(&mut self, additional: usize, avg_type_size: usize)

Reserves capacity for exactly additional more elements.

Since we do not type sizes ahead, an average type size avg_type_size must be specified.

§Panics

Panics if the new capacity overflows usize.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

Source

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

Shortens the vector to be len elements long.

Source

pub fn insert<T: Any>(&mut self, index: usize, element: T)

Inserts an element at position index in the vector.

Shifts elements after position index to the right.

§Panics

Panics if index is greater than the vector’s length.

Source

pub fn remove_and_return<T: Any>(&mut self, index: usize) -> Result<T, String>

Removes and returns the element at position index.

Shifts elements after position index to the left.

§Panics

Panics if index is out of bounds.

Source

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

Removes and returns the element at position index.

Shifts elements after position index to the left.

§Panics

Panics if index is out of bounds.

Source

pub fn is<T: Any>(&self, index: usize) -> Option<bool>

Returns if element at position index is of type T, or None if the index is out of bounds.

Source

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

Returns element at position index or None if the index is out of bounds.

Source

pub fn get_mut<T: Any>(&self, index: usize) -> Result<Option<&mut T>, String>

Returns mutable reference to element at position index, or None if the index is out of bounds.

Source

pub fn push<T: Any>(&mut self, value: T)

Appends an element to the back of a collection.

§Panics

Panics if the number of elements in the vector overflows a usize.

Source

pub fn pop<T: Any>(&mut self) -> Result<Option<T>, String>

Returns the last element of the vector, or None if it is empty.

Source

pub fn append(&mut self, other: &mut AnyVec)

Moves all the elements of other into Self, leaving other empty.

§Panics

Panics if the number of elements in the vector overflows a usize.

Source

pub fn clear(&mut self)

Clears the vector.

Source

pub fn len(&self) -> usize

Returns the number of elements in the vector.

Source

pub fn is_empty(&self) -> bool

Returns if the vector is empty.

Source

pub fn split_off(&mut self, at: usize) -> Self

Splits the collection into two at the given index.

§Panics

Panics if at > len.

Trait Implementations§

Source§

impl Debug for AnyVec

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for AnyVec

§

impl RefUnwindSafe for AnyVec

§

impl Send for AnyVec

§

impl Sync for AnyVec

§

impl Unpin for AnyVec

§

impl UnwindSafe for AnyVec

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.