pub struct AnyVec<Traits: ?Sized + Trait = dyn None, M: MemBuilder = Heap> { /* private fields */ }Expand description
Type erased vec-like container. All elements have the same type.
Only destruct and clone operations have indirect call overhead.
You can make AnyVec Send-able, Sync-able, Cloneable, by
specifying trait constraints: AnyVec<dyn Cloneable + Sync + Send>. See traits.
Some operations return TempValue<Operation>, which internally holds &mut to AnyVec.
You can drop it, cast to concrete type, or put into another vector. (See any_value)
T: 'static due to TypeId requirements
Implementations§
Source§impl<Traits: ?Sized + Trait, M: MemBuilder> AnyVec<Traits, M>
impl<Traits: ?Sized + Trait, M: MemBuilder> AnyVec<Traits, M>
Sourcepub fn new<T>() -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
M: Default,
pub fn new<T>() -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
M: Default,
Constructs empty AnyVec with elements of type T,
using Default MemBuilder.
T should satisfy requested Traits.
Not available, if provided MemBuilder is not Default.
Sourcepub fn new_in<T>(mem_builder: M) -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
pub fn new_in<T>(mem_builder: M) -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
Constructs empty AnyVec with elements of type T,
using provided mem_builder.
T should satisfy requested Traits.
Sourcepub fn with_capacity<T>(capacity: usize) -> Self
pub fn with_capacity<T>(capacity: usize) -> Self
Constructs empty AnyVec with specified capacity and
elements of type T, using Default MemBuilder.
T should satisfy requested Traits.
Not available, if provided MemBuilder is not
MemBuilderSizeable and Default.
Sourcepub fn with_capacity_in<T>(capacity: usize, mem_builder: M) -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
M: MemBuilderSizeable,
pub fn with_capacity_in<T>(capacity: usize, mem_builder: M) -> Selfwhere
T: SatisfyTraits<Traits> + 'static,
M: MemBuilderSizeable,
Constructs empty AnyVec with specified capacity and
elements of type T, using mem_builder.
T should satisfy requested Traits.
Not available, if provided MemBuilder is not
MemBuilderSizeable.
Sourcepub fn into_raw_parts(self) -> RawParts<M>where
M::Mem: MemRawParts,
pub fn into_raw_parts(self) -> RawParts<M>where
M::Mem: MemRawParts,
Destructure AnyVec into RawParts.
Sourcepub unsafe fn from_raw_parts(raw_parts: RawParts<M>) -> Selfwhere
M::Mem: MemRawParts,
pub unsafe fn from_raw_parts(raw_parts: RawParts<M>) -> Selfwhere
M::Mem: MemRawParts,
Sourcepub fn clone_empty(&self) -> Self
pub fn clone_empty(&self) -> Self
Sourcepub fn clone_empty_in<NewM: MemBuilder>(
&self,
mem_builder: NewM,
) -> AnyVec<Traits, NewM>
pub fn clone_empty_in<NewM: MemBuilder>( &self, mem_builder: NewM, ) -> AnyVec<Traits, NewM>
Constructs empty AnyVec with the same elements type and Traits,
but with other MemBuilder.
Use it to construct intermediate storage, with fast MemBuilder.
§Example
let mut tmp = any_vec.clone_empty_in(Stack::<256>);
tmp.push(any_vec.at(0).lazy_clone());
any_vec.push(tmp.pop().unwrap());Sourcepub fn reserve(&mut self, additional: usize)where
M::Mem: MemResizable,
pub fn reserve(&mut self, additional: usize)where
M::Mem: MemResizable,
Reserves capacity for at least additional more elements to be inserted
in the given container. More space may be reserved to avoid
frequent reallocations. After calling reserve, capacity will be
greater than or equal to self.len() + additional. Exact behavior defined by
implementation of MemResizable. Does nothing if capacity is already sufficient.
Not available, if provided MemBuilder::Mem is not MemResizable.
§Panics
MemResizable implementation may panic - see implementation description.
Sourcepub fn reserve_exact(&mut self, additional: usize)where
M::Mem: MemResizable,
pub fn reserve_exact(&mut self, additional: usize)where
M::Mem: MemResizable,
Reserves the minimum capacity for exactly additional more elements to
be inserted in the given container. After calling reserve_exact,
capacity will be greater than or equal to self.len() + additional.
Exact behavior defined by implementation of MemResizable.
Does nothing if the capacity is already sufficient.
Note that the Mem implementation may grow bigger then requested.
Therefore, capacity can not be relied upon to be precisely
minimal. Prefer reserve if future insertions are expected.
Not available, if provided MemBuilder::Mem is not MemResizable.
§Panics
MemResizable implementation may panic - see implementation description.
Sourcepub fn shrink_to_fit(&mut self)where
M::Mem: MemResizable,
pub fn shrink_to_fit(&mut self)where
M::Mem: MemResizable,
Shrinks the capacity as much as possible.
Exact behavior defined by implementation of MemResizable.
Not available, if provided MemBuilder::Mem is not MemResizable.
§Panics
MemResizable implementation may panic - see implementation description.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)where
M::Mem: MemResizable,
pub fn shrink_to(&mut self, min_capacity: usize)where
M::Mem: MemResizable,
Shrinks the capacity of the vector with a lower bound.
The capacity will remain at least as large as both the length
and the supplied value. Exact behavior defined by implementation of MemResizable.
If the current capacity is less than the lower limit, this is a no-op.
Not available, if provided MemBuilder::Mem is not MemResizable.
§Panics
MemResizable implementation may panic - see implementation description.
pub unsafe fn set_len(&mut self, new_len: usize)
Sourcepub fn downcast_ref<T: 'static>(&self) -> Option<AnyVecRef<'_, T, M>>
pub fn downcast_ref<T: 'static>(&self) -> Option<AnyVecRef<'_, T, M>>
Returns AnyVecRef - typed view to const AnyVec,
if container holds elements of type T, or None if it isn’t.
Sourcepub unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> AnyVecRef<'_, T, M>
pub unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> AnyVecRef<'_, T, M>
Sourcepub fn downcast_mut<T: 'static>(&mut self) -> Option<AnyVecMut<'_, T, M>>
pub fn downcast_mut<T: 'static>(&mut self) -> Option<AnyVecMut<'_, T, M>>
Returns AnyVecMut - typed view to mut AnyVec,
if container holds elements of type T, or None if it isn’t.
Sourcepub unsafe fn downcast_mut_unchecked<T: 'static>(
&mut self,
) -> AnyVecMut<'_, T, M>
pub unsafe fn downcast_mut_unchecked<T: 'static>( &mut self, ) -> AnyVecMut<'_, T, M>
pub fn as_bytes(&self) -> &[u8]
pub fn as_bytes_mut(&mut self) -> &mut [u8]
pub fn spare_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub fn iter(&self) -> IterRef<'_, Traits, M>
pub fn iter_mut(&mut self) -> IterMut<'_, Traits, M>
Sourcepub fn at(&self, index: usize) -> ElementRef<'_, Traits, M>
pub fn at(&self, index: usize) -> ElementRef<'_, Traits, M>
pub fn get(&self, index: usize) -> Option<ElementRef<'_, Traits, M>>
pub unsafe fn get_unchecked(&self, index: usize) -> ElementRef<'_, Traits, M>
Sourcepub fn at_mut(&mut self, index: usize) -> ElementMut<'_, Traits, M>
pub fn at_mut(&mut self, index: usize) -> ElementMut<'_, Traits, M>
Return mutable reference to element at index with bounds check.
§Panics
- Panics if index is out of bounds.
pub fn get_mut(&mut self, index: usize) -> Option<ElementMut<'_, Traits, M>>
pub unsafe fn get_unchecked_mut( &mut self, index: usize, ) -> ElementMut<'_, Traits, M>
Sourcepub fn insert<V: AnyValue>(&mut self, index: usize, value: V)
pub fn insert<V: AnyValue>(&mut self, index: usize, value: V)
§Panics
- Panics if type mismatch.
- Panics if index is out of bounds.
- Panics if out of memory.
Sourcepub unsafe fn insert_unchecked<V: AnyValueSizeless>(
&mut self,
index: usize,
value: V,
)
pub unsafe fn insert_unchecked<V: AnyValueSizeless>( &mut self, index: usize, value: V, )
Sourcepub fn push<V: AnyValue>(&mut self, value: V)
pub fn push<V: AnyValue>(&mut self, value: V)
§Panics
- Panics if type mismatch.
- Panics if out of memory.
Sourcepub unsafe fn push_unchecked<V: AnyValueSizeless>(&mut self, value: V)
pub unsafe fn push_unchecked<V: AnyValueSizeless>(&mut self, value: V)
Sourcepub fn pop(&mut self) -> Option<Pop<'_, Traits, M>>
pub fn pop(&mut self) -> Option<Pop<'_, Traits, M>>
§Leaking
If the returned TempValue goes out of scope without being dropped (due to
mem::forget, for example), the vector will lost and leak last element.
Sourcepub fn remove(&mut self, index: usize) -> Remove<'_, Traits, M>
pub fn remove(&mut self, index: usize) -> Remove<'_, Traits, M>
§Panics
Panics if index out of bounds.
§Leaking
If the returned TempValue goes out of scope without being dropped (due to
mem::forget, for example), the vector may have lost and leaked
elements with indices >= index.
Sourcepub fn swap_remove(&mut self, index: usize) -> SwapRemove<'_, Traits, M>
pub fn swap_remove(&mut self, index: usize) -> SwapRemove<'_, Traits, M>
§Panics
Panics if index out of bounds.
§Leaking
If the returned TempValue goes out of scope without being dropped (due to
mem::forget, for example), the vector may have lost and leaked
elements with indices >= index.
Sourcepub fn append<OtherTraits, OtherM>(
&mut self,
other: &mut AnyVec<OtherTraits, OtherM>,
)
pub fn append<OtherTraits, OtherM>( &mut self, other: &mut AnyVec<OtherTraits, OtherM>, )
Moves all the elements of other into self, leaving other empty.
§Panics
- Panics if types mismatch.
- Panics if out of memory.
Sourcepub fn drain(&mut self, range: impl RangeBounds<usize>) -> Drain<'_, Traits, M>
pub fn drain(&mut self, range: impl RangeBounds<usize>) -> Drain<'_, Traits, M>
Removes the specified range from the vector in bulk, returning all removed elements as an iterator. If the iterator is dropped before being fully consumed, it drops the remaining removed elements.
The returned iterator keeps a mutable borrow on the vector.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
§Leaking
If the returned iterator goes out of scope without being dropped (due to
mem::forget, for example), the vector may have lost and leaked
elements with indices in and past the range.
Sourcepub fn splice<I: IntoIterator>(
&mut self,
range: impl RangeBounds<usize>,
replace_with: I,
) -> Splice<'_, Traits, M, I::IntoIter>
pub fn splice<I: IntoIterator>( &mut self, range: impl RangeBounds<usize>, replace_with: I, ) -> Splice<'_, Traits, M, I::IntoIter>
Creates a splicing iterator that replaces the specified range in the vector
with the given replace_with iterator and yields the removed items.
replace_with does not need to be the same length as range.
range is removed even if the iterator is not consumed until the end.
The returned iterator keeps a mutable borrow on the vector.
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.
§Leaking
If the returned iterator goes out of scope without being dropped (due to
mem::forget, for example), the vector may have lost and leaked
elements with indices in and past the range.
pub fn clear(&mut self)
Sourcepub fn element_typeid(&self) -> TypeId
pub fn element_typeid(&self) -> TypeId
Element TypeId
Sourcepub fn element_layout(&self) -> Layout
pub fn element_layout(&self) -> Layout
Element Layout
Sourcepub fn element_drop(&self) -> Option<unsafe fn(ptr: *mut u8, len: usize)>
pub fn element_drop(&self) -> Option<unsafe fn(ptr: *mut u8, len: usize)>
Element drop function.
len - elements count.
None - drop is not needed.
Sourcepub fn element_clone(
&self,
) -> unsafe fn(src: *const u8, dst: *mut u8, len: usize)where
Traits: Cloneable,
pub fn element_clone(
&self,
) -> unsafe fn(src: *const u8, dst: *mut u8, len: usize)where
Traits: Cloneable,
Element clone function.
len - elements count.
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn capacity(&self) -> usize
Trait Implementations§
Source§impl<Traits, M, A> Extend<A> for AnyVec<Traits, M>
impl<Traits, M, A> Extend<A> for AnyVec<Traits, M>
Source§fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T)
§Panics
- Panics if type mismatch.
- Panics if out of memory.
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)