AnyVec

Struct AnyVec 

Source
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>

Source

pub fn new<T>() -> Self
where 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.

Source

pub fn new_in<T>(mem_builder: M) -> Self
where T: SatisfyTraits<Traits> + 'static,

Constructs empty AnyVec with elements of type T, using provided mem_builder.

T should satisfy requested Traits.

Source

pub fn with_capacity<T>(capacity: usize) -> Self
where T: SatisfyTraits<Traits> + 'static, M: MemBuilderSizeable + Default,

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.

Source

pub fn with_capacity_in<T>(capacity: usize, mem_builder: M) -> Self
where 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.

Source

pub fn into_raw_parts(self) -> RawParts<M>
where M::Mem: MemRawParts,

Destructure AnyVec into RawParts.

Source

pub unsafe fn from_raw_parts(raw_parts: RawParts<M>) -> Self
where M::Mem: MemRawParts,

Construct AnyVec from previously deconstructed raw parts.

§Safety
§Traits

Traits validity not checked. RawParts of underlying type must implement Traits. It is not safe to opt-in Cloneable, if initial AnyVec was not constructed with that trait.

§RawParts

RawParts validity not checked.

Source

pub fn clone_empty(&self) -> Self

Constructs empty AnyVec with the same elements type, Traits and MemBuilder. IOW, same as clone, but without elements copy.

Source

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());
Source

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.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn set_len(&mut self, new_len: usize)

Source

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.

Source

pub unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> AnyVecRef<'_, T, M>

Returns AnyVecRef - typed view to const AnyVec.

§Safety

The container elements must be of type T. Calling this method with the incorrect type is undefined behavior.

Source

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.

Source

pub unsafe fn downcast_mut_unchecked<T: 'static>( &mut self, ) -> AnyVecMut<'_, T, M>

Returns AnyVecMut - typed view to mut AnyVec.

§Safety

The container elements must be of type T. Calling this method with the incorrect type is undefined behavior.

Source

pub fn as_bytes(&self) -> &[u8]

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Source

pub fn spare_bytes_mut(&mut self) -> &mut [MaybeUninit<u8>]

Source

pub fn iter(&self) -> IterRef<'_, Traits, M>

Source

pub fn iter_mut(&mut self) -> IterMut<'_, Traits, M>

Source

pub fn at(&self, index: usize) -> ElementRef<'_, Traits, M>

Return reference to element at index with bounds check.

§Panics
  • Panics if index is out of bounds.
Source

pub fn get(&self, index: usize) -> Option<ElementRef<'_, Traits, M>>

Source

pub unsafe fn get_unchecked(&self, index: usize) -> ElementRef<'_, Traits, M>

Source

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.
Source

pub fn get_mut(&mut self, index: usize) -> Option<ElementMut<'_, Traits, M>>

Source

pub unsafe fn get_unchecked_mut( &mut self, index: usize, ) -> ElementMut<'_, Traits, M>

Source

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.
Source

pub unsafe fn insert_unchecked<V: AnyValueSizeless>( &mut self, index: usize, value: V, )

Same as insert, but without type checks.

§Panics
  • Panics if index is out of bounds.
  • Panics if out of memory.
§Safety

Type not checked.

Source

pub fn push<V: AnyValue>(&mut self, value: V)

§Panics
  • Panics if type mismatch.
  • Panics if out of memory.
Source

pub unsafe fn push_unchecked<V: AnyValueSizeless>(&mut self, value: V)

Same as push, but without type checks.

§Panics

Panics if out of memory.

§Safety

Type not checked.

Source

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.

Source

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.

Source

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.

Source

pub fn append<OtherTraits, OtherM>( &mut self, other: &mut AnyVec<OtherTraits, OtherM>, )
where OtherTraits: ?Sized + Trait, OtherM: MemBuilder,

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

§Panics
  • Panics if types mismatch.
  • Panics if out of memory.
Source

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.

Source

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.

Source

pub fn clear(&mut self)

Source

pub fn element_typeid(&self) -> TypeId

Element TypeId

Source

pub fn element_layout(&self) -> Layout

Element Layout

Source

pub fn element_drop(&self) -> Option<unsafe fn(ptr: *mut u8, len: usize)>

Element drop function.

len - elements count. None - drop is not needed.

Source

pub fn element_clone( &self, ) -> unsafe fn(src: *const u8, dst: *mut u8, len: usize)
where Traits: Cloneable,

Element clone function.

len - elements count.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn capacity(&self) -> usize

Trait Implementations§

Source§

impl<Traits: ?Sized + Cloneable + Trait, M: MemBuilder> Clone for AnyVec<Traits, M>

Source§

fn clone(&self) -> Self

Returns a duplicate 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<Traits: ?Sized + Trait, M: MemBuilder> Debug for AnyVec<Traits, M>

Source§

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

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

impl<Traits, M, A> Extend<A> for AnyVec<Traits, M>
where Traits: ?Sized + Trait, M: MemBuilder, A: AnyValue,

Source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<'a, Traits: ?Sized + Trait, M: MemBuilder> IntoIterator for &'a AnyVec<Traits, M>

Source§

type Item = ElementRef<'a, Traits, M>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, AnyVecPtr<Traits, M>, ElementRefIterItem<'a, Traits, M>>

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<'a, Traits: ?Sized + Trait, M: MemBuilder> IntoIterator for &'a mut AnyVec<Traits, M>

Source§

type Item = ElementMut<'a, Traits, M>

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, AnyVecPtr<Traits, M>, ElementMutIterItem<'a, Traits, M>>

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<Traits: ?Sized + Send + Trait, M: MemBuilder + Send> Send for AnyVec<Traits, M>
where M::Mem: Send,

Source§

impl<Traits: ?Sized + Sync + Trait, M: MemBuilder + Sync> Sync for AnyVec<Traits, M>
where M::Mem: Sync,

Auto Trait Implementations§

§

impl<Traits, M> Freeze for AnyVec<Traits, M>
where <Traits as CloneType>::Type: Freeze, M: Freeze, <M as MemBuilder>::Mem: Freeze, Traits: ?Sized,

§

impl<Traits, M> RefUnwindSafe for AnyVec<Traits, M>
where <Traits as CloneType>::Type: RefUnwindSafe, M: RefUnwindSafe, <M as MemBuilder>::Mem: RefUnwindSafe, Traits: RefUnwindSafe + ?Sized,

§

impl<Traits, M> Unpin for AnyVec<Traits, M>
where <Traits as CloneType>::Type: Unpin, M: Unpin, <M as MemBuilder>::Mem: Unpin, Traits: Unpin + ?Sized,

§

impl<Traits, M> UnwindSafe for AnyVec<Traits, M>
where <Traits as CloneType>::Type: UnwindSafe, M: UnwindSafe, <M as MemBuilder>::Mem: UnwindSafe, Traits: UnwindSafe + ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

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 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.
Source§

impl<T> SatisfyTraits<dyn Cloneable> for T
where T: Clone,

Source§

impl<T> SatisfyTraits<dyn Cloneable + Send> for T
where T: Clone + Send,

Source§

impl<T> SatisfyTraits<dyn Cloneable + Sync + Send> for T
where T: Clone + Send + Sync,

Source§

impl<T> SatisfyTraits<dyn Cloneable + Sync> for T
where T: Clone + Sync,

Source§

impl<T> SatisfyTraits<dyn None> for T

Source§

impl<T> SatisfyTraits<dyn Send> for T
where T: Send,

Source§

impl<T> SatisfyTraits<dyn Sync + Send> for T
where T: Send + Sync,

Source§

impl<T> SatisfyTraits<dyn Sync> for T
where T: Sync,