| 1 | use crate::{ |
| 2 | Capacity, Clear, Collection, CollectionMut, CollectionRef, Get, GetKeyValue, GetKeyValueMut, |
| 3 | GetMut, Iter, IterMut, Keyed, KeyedRef, Len, MapInsert, MapIter, MapIterMut, PopBack, PushBack, |
| 4 | Remove, Reserve, SimpleCollectionMut, SimpleCollectionRef, SimpleKeyedRef, WithCapacity, |
| 5 | }; |
| 6 | use ijson::{IArray, IObject, IString, IValue}; |
| 7 | |
| 8 | impl Collection for IObject { |
| 9 | type Item = IValue; |
| 10 | } |
| 11 | |
| 12 | impl CollectionRef for IObject { |
| 13 | type ItemRef<'a> = &'a IValue where Self: 'a; |
| 14 | |
| 15 | crate::covariant_item_ref!(); |
| 16 | } |
| 17 | |
| 18 | impl CollectionMut for IObject { |
| 19 | type ItemMut<'a> = &'a mut IValue where Self: 'a; |
| 20 | |
| 21 | crate::covariant_item_mut!(); |
| 22 | } |
| 23 | |
| 24 | impl SimpleCollectionRef for IObject { |
| 25 | crate::simple_collection_ref!(); |
| 26 | } |
| 27 | |
| 28 | impl SimpleCollectionMut for IObject { |
| 29 | crate::simple_collection_mut!(); |
| 30 | } |
| 31 | |
| 32 | impl Keyed for IObject { |
| 33 | type Key = IString; |
| 34 | } |
| 35 | |
| 36 | impl KeyedRef for IObject { |
| 37 | type KeyRef<'a> = &'a IString where Self: 'a; |
| 38 | |
| 39 | crate::covariant_key_ref!(); |
| 40 | } |
| 41 | |
| 42 | impl SimpleKeyedRef for IObject { |
| 43 | crate::simple_keyed_ref!(); |
| 44 | } |
| 45 | |
| 46 | impl Len for IObject { |
| 47 | #[inline(always)] |
| 48 | fn len(&self) -> usize { |
| 49 | self.len() |
| 50 | } |
| 51 | |
| 52 | #[inline(always)] |
| 53 | fn is_empty(&self) -> bool { |
| 54 | self.is_empty() |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl MapIter for IObject { |
| 59 | type Iter<'a> = ijson::object::Iter<'a>; |
| 60 | |
| 61 | #[inline(always)] |
| 62 | fn iter(&self) -> Self::Iter<'_> { |
| 63 | self.iter() |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl MapIterMut for IObject { |
| 68 | type IterMut<'a> = ijson::object::IterMut<'a> where Self: 'a; |
| 69 | |
| 70 | #[inline(always)] |
| 71 | fn iter_mut(&mut self) -> Self::IterMut<'_> { |
| 72 | self.iter_mut() |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | impl<Q: ijson::object::ObjectIndex> Get<Q> for IObject { |
| 77 | #[inline(always)] |
| 78 | fn get(&self, q: Q) -> Option<&IValue> { |
| 79 | self.get(q) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | impl<Q: ijson::object::ObjectIndex> GetKeyValue<Q> for IObject { |
| 84 | #[inline(always)] |
| 85 | fn get_key_value(&self, q: Q) -> Option<(&IString, &IValue)> { |
| 86 | self.get_key_value(q) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | impl<Q: ijson::object::ObjectIndex> GetMut<Q> for IObject { |
| 91 | #[inline(always)] |
| 92 | fn get_mut(&mut self, q: Q) -> Option<&mut IValue> { |
| 93 | self.get_mut(q) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | impl<Q: ijson::object::ObjectIndex> GetKeyValueMut<Q> for IObject { |
| 98 | #[inline(always)] |
| 99 | fn get_key_value_mut(&mut self, q: Q) -> Option<(&IString, &mut IValue)> { |
| 100 | self.get_key_value_mut(q) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | impl MapInsert<IString> for IObject { |
| 105 | type Output = Option<IValue>; |
| 106 | |
| 107 | #[inline(always)] |
| 108 | fn insert(&mut self, key: IString, value: IValue) -> Option<IValue> { |
| 109 | self.insert(key, value) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | impl<Q: ijson::object::ObjectIndex> Remove<Q> for IObject { |
| 114 | #[inline(always)] |
| 115 | fn remove(&mut self, key: Q) -> Option<IValue> { |
| 116 | self.remove(key) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | impl Clear for IObject { |
| 121 | #[inline(always)] |
| 122 | fn clear(&mut self) { |
| 123 | self.clear() |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | impl Collection for IArray { |
| 128 | type Item = IValue; |
| 129 | } |
| 130 | |
| 131 | impl CollectionRef for IArray { |
| 132 | type ItemRef<'a> = &'a IValue where Self: 'a; |
| 133 | |
| 134 | crate::covariant_item_ref!(); |
| 135 | } |
| 136 | |
| 137 | impl CollectionMut for IArray { |
| 138 | type ItemMut<'a> = &'a mut IValue where Self: 'a; |
| 139 | |
| 140 | crate::covariant_item_mut!(); |
| 141 | } |
| 142 | |
| 143 | impl WithCapacity for IArray { |
| 144 | #[inline(always)] |
| 145 | fn with_capacity(capacity: usize) -> Self { |
| 146 | Self::with_capacity(capacity) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | impl Len for IArray { |
| 151 | #[inline(always)] |
| 152 | fn len(&self) -> usize { |
| 153 | self.len() |
| 154 | } |
| 155 | |
| 156 | #[inline(always)] |
| 157 | fn is_empty(&self) -> bool { |
| 158 | self.is_empty() |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl Get<usize> for IArray { |
| 163 | #[inline(always)] |
| 164 | fn get(&self, index: usize) -> Option<&IValue> { |
| 165 | self.as_slice().get(index) |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | impl GetMut<usize> for IArray { |
| 170 | #[inline(always)] |
| 171 | fn get_mut(&mut self, index: usize) -> Option<&mut IValue> { |
| 172 | self.as_mut_slice().get_mut(index) |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | impl Capacity for IArray { |
| 177 | #[inline(always)] |
| 178 | fn capacity(&self) -> usize { |
| 179 | self.capacity() |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | impl Reserve for IArray { |
| 184 | #[inline(always)] |
| 185 | fn reserve(&mut self, additional: usize) { |
| 186 | self.reserve(additional) |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | impl PushBack for IArray { |
| 191 | type Output = (); |
| 192 | |
| 193 | #[inline(always)] |
| 194 | fn push_back(&mut self, t: IValue) { |
| 195 | self.push(t) |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | impl PopBack for IArray { |
| 200 | #[inline(always)] |
| 201 | fn pop_back(&mut self) -> Option<IValue> { |
| 202 | self.pop() |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | impl Remove<usize> for IArray { |
| 207 | #[inline(always)] |
| 208 | fn remove(&mut self, index: usize) -> Option<IValue> { |
| 209 | if index < self.len() { |
| 210 | self.remove(index) |
| 211 | } else { |
| 212 | None |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | impl Clear for IArray { |
| 218 | #[inline(always)] |
| 219 | fn clear(&mut self) { |
| 220 | self.clear() |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | impl Iter for IArray { |
| 225 | type Iter<'a> = std::slice::Iter<'a, IValue>; |
| 226 | |
| 227 | #[inline(always)] |
| 228 | fn iter(&self) -> Self::Iter<'_> { |
| 229 | self.as_slice().iter() |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | impl IterMut for IArray { |
| 234 | type IterMut<'a> = std::slice::IterMut<'a, IValue>; |
| 235 | |
| 236 | #[inline(always)] |
| 237 | fn iter_mut(&mut self) -> Self::IterMut<'_> { |
| 238 | self.as_mut_slice().iter_mut() |
| 239 | } |
| 240 | } |