webrender::util

Trait VecHelper

Source
pub trait VecHelper<T> {
    // Required methods
    fn alloc(&mut self) -> Allocation<'_, T>;
    fn entry(&mut self, index: usize) -> VecEntry<'_, T>;
    fn take(&mut self) -> Self;
    fn take_and_preallocate(&mut self) -> Self;
}

Required Methods§

Source

fn alloc(&mut self) -> Allocation<'_, T>

Growns the vector by a single entry, returning the allocation.

Source

fn entry(&mut self, index: usize) -> VecEntry<'_, T>

Either returns an existing elemenet, or grows the vector by one. Doesn’t expect indices to be higher than the current length.

Source

fn take(&mut self) -> Self

Equivalent to mem::replace(&mut vec, Vec::new())

Source

fn take_and_preallocate(&mut self) -> Self

Functionally equivalent to mem::replace(&mut vec, Vec::new()) but tries to keep the allocation in the caller if it is empty or replace it with a pre-allocated vector.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> VecHelper<T> for Vec<T>

Source§

fn alloc(&mut self) -> Allocation<'_, T>

Source§

fn entry(&mut self, index: usize) -> VecEntry<'_, T>

Source§

fn take(&mut self) -> Self

Source§

fn take_and_preallocate(&mut self) -> Self

Implementors§