MCPcopy Create free account
hub / github.com/Lokathor/tinyvec / insert

Method insert

src/tinyvec.rs:928–949  ·  view source on GitHub ↗
(&mut self, index: usize, item: A::Item)

Source from the content-addressed store, hash-verified

926 /// ```
927 #[inline]
928 pub fn insert(&mut self, index: usize, item: A::Item) {
929 assert!(
930 index <= self.len(),
931 "insertion index (is {}) should be <= len (is {})",
932 index,
933 self.len()
934 );
935
936 let arr = match self {
937 TinyVec::Heap(v) => return v.insert(index, item),
938 TinyVec::Inline(a) => a,
939 };
940
941 if let Some(x) = arr.try_insert(index, item) {
942 let mut v = Vec::with_capacity(arr.len() * 2);
943 let mut it = arr.iter_mut().map(core::mem::take);
944 v.extend(it.by_ref().take(index));
945 v.push(x);
946 v.extend(it);
947 *self = TinyVec::Heap(v);
948 }
949 }
950
951 /// If the vec is empty.
952 #[inline(always)]

Callers 1

dropMethod · 0.45

Calls 4

try_insertMethod · 0.80
lenMethod · 0.45
extendMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected