use alloc::vec::Vec;
pub trait VecExtensions<T> {
fn push_if_empty(self, value: T) -> Self;
fn swap_insert(&mut self, index: usize, value: T);
fn merge(self, other: Self) -> Self;
}
impl<T> VecExtensions<T> for Vec<T> {
fn push_if_empty(mut self, value: T) -> Self {
if self.is_empty() {
self.push(value);
}
self
}
fn swap_insert(&mut self, index: usize, value: T) {
self.push(value);
let loc = self.len() - 1;
self.swap(index, loc);
}
fn merge(mut self, mut other: Self) -> Self {
self.append(&mut other);
self
}
}