use core::cmp::Ordering;
pub trait VecExt<T> {
fn appended(self, other: &mut Self) -> Self;
fn cleared(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 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, f: F) -> Self
where
F: FnMut(&T) -> K,
K: Ord;
fn truncated(self, len: usize) -> Self;
}
impl<T> VecExt<T> for super::lib::vec::Vec<T> {
fn appended(mut self, other: &mut Self) -> Self {
self.append(other);
self
}
fn cleared(mut self) -> Self {
self.clear();
self
}
fn deduped(mut self) -> Self
where
T: PartialEq,
{
self.dedup();
self
}
fn deduped_by<F>(mut self, same_bucket: F) -> Self
where
F: FnMut(&mut T, &mut T) -> bool,
{
self.dedup_by(same_bucket);
self
}
fn deduped_by_key<F, K>(mut self, key: F) -> Self
where
F: FnMut(&mut T) -> K,
K: PartialEq<K>,
{
self.dedup_by_key(key);
self
}
fn resized(mut self, new_len: usize, value: T) -> Self
where
T: Clone,
{
self.resize(new_len, value);
self
}
fn reversed(mut self) -> Self {
self.reverse();
self
}
fn shrinked_to_fit(mut self) -> Self {
self.shrink_to_fit();
self
}
fn sorted(mut self) -> Self
where
T: Ord,
{
self.sort();
self
}
fn sorted_by<F>(mut self, compare: F) -> Self
where
F: FnMut(&T, &T) -> Ordering,
{
self.sort_by(compare);
self
}
fn sorted_by_key<F, K>(mut self, f: F) -> Self
where
F: FnMut(&T) -> K,
K: Ord,
{
self.sort_by_key(f);
self
}
fn truncated(mut self, len: usize) -> Self {
self.truncate(len);
self
}
}