| 1 | use crate::{ |
| 2 | Capacity, Clear, Collection, CollectionMut, CollectionRef, Get, GetMut, Iter, IterMut, Len, |
| 3 | PopBack, PushBack, Remove, Reserve, SimpleCollectionMut, SimpleCollectionRef, WithCapacity, |
| 4 | }; |
| 5 | use alloc::vec::Vec; |
| 6 | |
| 7 | impl<T> Collection for Vec<T> { |
| 8 | type Item = T; |
| 9 | } |
| 10 | |
| 11 | impl<T> CollectionRef for Vec<T> { |
| 12 | type ItemRef<'a> = &'a T where Self: 'a; |
| 13 | |
| 14 | crate::covariant_item_ref!(); |
| 15 | } |
| 16 | |
| 17 | impl<T> CollectionMut for Vec<T> { |
| 18 | type ItemMut<'a> = &'a mut T where Self: 'a; |
| 19 | |
| 20 | crate::covariant_item_mut!(); |
| 21 | } |
| 22 | |
| 23 | impl<T> SimpleCollectionRef for Vec<T> { |
| 24 | crate::simple_collection_ref!(); |
| 25 | } |
| 26 | |
| 27 | impl<T> SimpleCollectionMut for Vec<T> { |
| 28 | crate::simple_collection_mut!(); |
| 29 | } |
| 30 | |
| 31 | impl<T> WithCapacity for Vec<T> { |
| 32 | #[inline(always)] |
| 33 | fn with_capacity(capacity: usize) -> Self { |
| 34 | Vec::with_capacity(capacity) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | impl<T> Len for Vec<T> { |
| 39 | #[inline(always)] |
| 40 | fn len(&self) -> usize { |
| 41 | self.len() |
| 42 | } |
| 43 | |
| 44 | #[inline(always)] |
| 45 | fn is_empty(&self) -> bool { |
| 46 | self.is_empty() |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | impl<T> Get<usize> for Vec<T> { |
| 51 | #[inline(always)] |
| 52 | fn get(&self, index: usize) -> Option<&T> { |
| 53 | self.as_slice().get(index) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl<T> GetMut<usize> for Vec<T> { |
| 58 | #[inline(always)] |
| 59 | fn get_mut(&mut self, index: usize) -> Option<&mut T> { |
| 60 | self.as_mut_slice().get_mut(index) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl<T> Capacity for Vec<T> { |
| 65 | #[inline(always)] |
| 66 | fn capacity(&self) -> usize { |
| 67 | self.capacity() |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | impl<T> Reserve for Vec<T> { |
| 72 | #[inline(always)] |
| 73 | fn reserve(&mut self, additional: usize) { |
| 74 | self.reserve(additional) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | impl<T> PushBack for Vec<T> { |
| 79 | type Output = (); |
| 80 | |
| 81 | #[inline(always)] |
| 82 | fn push_back(&mut self, t: T) { |
| 83 | self.push(t) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | impl<T> PopBack for Vec<T> { |
| 88 | #[inline(always)] |
| 89 | fn pop_back(&mut self) -> Option<T> { |
| 90 | self.pop() |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | impl<T> Remove<usize> for Vec<T> { |
| 95 | #[inline(always)] |
| 96 | fn remove(&mut self, index: usize) -> Option<T> { |
| 97 | if index < self.len() { |
| 98 | Some(self.remove(index)) |
| 99 | } else { |
| 100 | None |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | impl<T> Clear for Vec<T> { |
| 106 | #[inline(always)] |
| 107 | fn clear(&mut self) { |
| 108 | self.clear() |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | impl<T> Iter for Vec<T> { |
| 113 | type Iter<'a> = core::slice::Iter<'a, T> where Self: 'a; |
| 114 | |
| 115 | #[inline(always)] |
| 116 | fn iter(&self) -> Self::Iter<'_> { |
| 117 | self.as_slice().iter() |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | impl<T> IterMut for Vec<T> { |
| 122 | type IterMut<'a> = core::slice::IterMut<'a, T> where Self: 'a; |
| 123 | |
| 124 | #[inline(always)] |
| 125 | fn iter_mut(&mut self) -> Self::IterMut<'_> { |
| 126 | self.as_mut_slice().iter_mut() |
| 127 | } |
| 128 | } |