[][src]Trait recycle::VecExt

pub trait VecExt: Sized {
    type T;
    fn try_map<U, R: Try<Ok = U>, F: FnMut(Self::T) -> R>(
        self,
        f: F
    ) -> Result<Vec<U>, R::Error>;
fn recycle<U>(self) -> Vec<U>; fn map<U, F: FnMut(Self::T) -> U>(self, f: F) -> Vec<U> { ... } }

Extension methods for Vec<T>

Associated Types

type T

The type that the Vec<T> stores

Loading content...

Required methods

fn try_map<U, R: Try<Ok = U>, F: FnMut(Self::T) -> R>(
    self,
    f: F
) -> Result<Vec<U>, R::Error>

Map a vector to another vector, will try and reuse the allocation if the allocation layouts of the two types match, i.e. if std::alloc::Layout::<T>::new() == std::alloc::Layout::<U>::new() then the allocation will be reused

The mapping function can be fallible, and on early return, it will drop all previous values, and the rest of the input vector. Thre error will be returned as a Result

fn recycle<U>(self) -> Vec<U>

Drops all of the values in the vector and create a new vector from it if the layouts are compatible

if layouts are not compatible, then return Vec::new()

Loading content...

Provided methods

fn map<U, F: FnMut(Self::T) -> U>(self, f: F) -> Vec<U>

Map a vector to another vector, will try and reuse the allocation if the allocation layouts of the two types match, i.e. if std::alloc::Layout::<T>::new() == std::alloc::Layout::<U>::new() then the allocation will be reused

Loading content...

Implementations on Foreign Types

impl<T> VecExt for Vec<T>[src]

type T = T

Loading content...

Implementors

Loading content...