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
impl AnyVec
Sourcepub fn with_capacity(capacity: usize, avg_type_size: usize) -> Self
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.
Sourcepub fn capacity(&self, type_size: usize) -> usize
pub fn capacity(&self, type_size: usize) -> usize
Returns the number of elements the vector can hold without reallocating.
Sourcepub fn reserve(&mut self, additional: usize, avg_type_size: usize)
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.
Sourcepub fn reserve_exact(&mut self, additional: usize, avg_type_size: usize)
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.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.
Sourcepub fn insert<T: Any>(&mut self, index: usize, element: T)
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.
Sourcepub fn remove_and_return<T: Any>(&mut self, index: usize) -> Result<T, String>
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.
Sourcepub fn remove(&mut self, index: usize)
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.
Sourcepub fn is<T: Any>(&self, index: usize) -> Option<bool>
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.
Sourcepub fn get<T: Any>(&self, index: usize) -> Result<Option<&T>, String>
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.
Sourcepub fn get_mut<T: Any>(&self, index: usize) -> Result<Option<&mut T>, String>
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.
Sourcepub fn push<T: Any>(&mut self, value: T)
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.
Sourcepub fn pop<T: Any>(&mut self) -> Result<Option<T>, String>
pub fn pop<T: Any>(&mut self) -> Result<Option<T>, String>
Returns the last element of the vector, or None if it is empty.