(&mut self, index: usize, item: A::Item)
| 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)] |
no test coverage detected