VecExt

Trait VecExt 

Source
pub trait VecExt<T> {
Show 14 methods // Required methods unsafe fn new_uninitialized(len: usize) -> Self; fn appended(self, other: &mut Self) -> Self; fn deduped(self) -> Self where T: PartialEq; fn deduped_by<F>(self, same_bucket: F) -> Self where F: FnMut(&mut T, &mut T) -> bool; fn deduped_by_key<F, K>(self, key: F) -> Self where F: FnMut(&mut T) -> K, K: PartialEq<K>; fn resized(self, new_len: usize, value: T) -> Self where T: Clone; fn reversed(self) -> Self; fn shrinked_to_fit(self) -> Self; fn shuffled(self) -> Self; fn shuffled_with<R: Rng>(self, rng: R) -> Self; fn sorted(self) -> Self where T: Ord; fn sorted_by<F>(self, compare: F) -> Self where F: FnMut(&T, &T) -> Ordering; fn sorted_by_key<F, K>(self, key: F) -> Self where F: FnMut(&T) -> K, K: Ord; fn truncated(self, len: usize) -> Self;
}
Expand description

An extension trait for std::vec::Vec.

Methods with the suffix ed are like the original methods, but consumes the vector. This is interesting to chain methods call. For example:

use fera_ext::VecExt;

assert_eq!(vec![1, 2, 3], vec![4, 3, 1, 3, 4, 2].sorted().deduped().truncated(3));

Required Methods§

Source

unsafe fn new_uninitialized(len: usize) -> Self

Creates a new vector with len uninitialized elements.

§Safety

This is unsafe because some values may not be dropped or some values may be dropped without being initialized. See std::mem::uninitialized for more informations.

Source

fn appended(self, other: &mut Self) -> Self

Source

fn deduped(self) -> Self
where T: PartialEq,

Source

fn deduped_by<F>(self, same_bucket: F) -> Self
where F: FnMut(&mut T, &mut T) -> bool,

Source

fn deduped_by_key<F, K>(self, key: F) -> Self
where F: FnMut(&mut T) -> K, K: PartialEq<K>,

Source

fn resized(self, new_len: usize, value: T) -> Self
where T: Clone,

Source

fn reversed(self) -> Self

Source

fn shrinked_to_fit(self) -> Self

Source

fn shuffled(self) -> Self

Shuffle this vector using SmallRng::from_entropy().

Source

fn shuffled_with<R: Rng>(self, rng: R) -> Self

Shuffle this vector using rng.

Source

fn sorted(self) -> Self
where T: Ord,

Source

fn sorted_by<F>(self, compare: F) -> Self
where F: FnMut(&T, &T) -> Ordering,

Source

fn sorted_by_key<F, K>(self, key: F) -> Self
where F: FnMut(&T) -> K, K: Ord,

Source

fn truncated(self, len: usize) -> Self

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> VecExt<T> for Vec<T>

Source§

unsafe fn new_uninitialized(size: usize) -> Self

Source§

fn deduped(self) -> Self
where T: PartialEq,

Source§

fn deduped_by<F>(self, same_bucket: F) -> Self
where F: FnMut(&mut T, &mut T) -> bool,

Source§

fn deduped_by_key<F, K>(self, key: F) -> Self
where F: FnMut(&mut T) -> K, K: PartialEq<K>,

Source§

fn appended(self, other: &mut Self) -> Self

Source§

fn resized(self, new_len: usize, value: T) -> Self
where T: Clone,

Source§

fn reversed(self) -> Self

Source§

fn shrinked_to_fit(self) -> Self

Source§

fn shuffled(self) -> Self

Source§

fn shuffled_with<R: Rng>(self, rng: R) -> Self

Source§

fn sorted(self) -> Self
where T: Ord,

Source§

fn sorted_by<F>(self, compare: F) -> Self
where F: FnMut(&T, &T) -> Ordering,

Source§

fn sorted_by_key<F, K>(self, key: F) -> Self
where F: FnMut(&T) -> K, K: Ord,

Source§

fn truncated(self, len: usize) -> Self

Implementors§