pub trait VecExt: Sized {
type T;
// Required methods
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>;
// Provided method
fn map<U, F: FnMut(Self::T) -> U>(self, f: F) -> Vec<U> { ... }
}
Expand description
Extension methods for Vec<T>
Required Associated Types§
Required Methods§
Sourcefn try_map<U, R: Try<Ok = U>, F: FnMut(Self::T) -> R>(
self,
f: F,
) -> Result<Vec<U>, R::Error>
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
Provided Methods§
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.