2023-04-14 10:39:11 +00:00
|
|
|
/// Collection where an item can be inserted at a given index.
|
|
|
|
pub trait InsertIndex: cc_traits::Collection {
|
|
|
|
type Output;
|
|
|
|
|
|
|
|
fn insert_index(
|
|
|
|
&mut self,
|
|
|
|
index: usize,
|
|
|
|
element: <Self as cc_traits::Collection>::Item,
|
|
|
|
) -> Self::Output;
|
|
|
|
}
|
|
|
|
|
2024-03-15 19:15:21 +00:00
|
|
|
#[cfg(feature = "std")]
|
2023-04-14 10:39:11 +00:00
|
|
|
impl<T> InsertIndex for Vec<T> {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
fn insert_index(&mut self, index: usize, element: T) {
|
|
|
|
self.insert(index, element)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "smallvec")]
|
|
|
|
impl<T, A: smallvec::Array<Item = T>> InsertIndex for smallvec::SmallVec<A> {
|
|
|
|
type Output = ();
|
|
|
|
|
|
|
|
fn insert_index(&mut self, index: usize, element: T) {
|
|
|
|
self.insert(index, element)
|
|
|
|
}
|
|
|
|
}
|