| 1 | use crate::{ |
| 2 | Capacity, Clear, Collection, CollectionMut, CollectionRef, Get, GetMut, Insert, Len, Remove, |
| 3 | Reserve, SimpleCollectionMut, SimpleCollectionRef, WithCapacity, |
| 4 | }; |
| 5 | use slab::Slab; |
| 6 | |
| 7 | impl<T> Collection for Slab<T> { |
| 8 | type Item = T; |
| 9 | } |
| 10 | |
| 11 | impl<T> CollectionRef for Slab<T> { |
| 12 | type ItemRef<'a> = &'a T where Self: 'a; |
| 13 | |
| 14 | crate::covariant_item_ref!(); |
| 15 | } |
| 16 | |
| 17 | impl<T> CollectionMut for Slab<T> { |
| 18 | type ItemMut<'a> = &'a mut T where Self: 'a; |
| 19 | |
| 20 | crate::covariant_item_mut!(); |
| 21 | } |
| 22 | |
| 23 | impl<T> SimpleCollectionRef for Slab<T> { |
| 24 | crate::simple_collection_ref!(); |
| 25 | } |
| 26 | |
| 27 | impl<T> SimpleCollectionMut for Slab<T> { |
| 28 | crate::simple_collection_mut!(); |
| 29 | } |
| 30 | |
| 31 | impl<T> WithCapacity for Slab<T> { |
| 32 | fn with_capacity(capacity: usize) -> Self { |
| 33 | Slab::with_capacity(capacity) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | impl<T> Len for Slab<T> { |
| 38 | fn len(&self) -> usize { |
| 39 | self.len() |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | impl<T> Capacity for Slab<T> { |
| 44 | fn capacity(&self) -> usize { |
| 45 | self.capacity() |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | impl<T> Reserve for Slab<T> { |
| 50 | fn reserve(&mut self, additional: usize) { |
| 51 | self.reserve(additional) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | impl<T> Get<usize> for Slab<T> { |
| 56 | fn get(&self, key: usize) -> Option<&Self::Item> { |
| 57 | self.get(key) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | impl<T> GetMut<usize> for Slab<T> { |
| 62 | fn get_mut(&mut self, key: usize) -> Option<&mut Self::Item> { |
| 63 | self.get_mut(key) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl<T> Insert for Slab<T> { |
| 68 | type Output = usize; |
| 69 | |
| 70 | fn insert(&mut self, element: T) -> usize { |
| 71 | self.insert(element) |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | impl<T> Remove<usize> for Slab<T> { |
| 76 | fn remove(&mut self, key: usize) -> Option<T> { |
| 77 | if self.contains(key) { |
| 78 | Some(self.remove(key)) |
| 79 | } else { |
| 80 | None |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | impl<T> Clear for Slab<T> { |
| 86 | fn clear(&mut self) { |
| 87 | self.clear() |
| 88 | } |
| 89 | } |