1use crate::error::Error;
10use crate::value::Value;
11use alloc::string::String;
12#[cfg(feature = "preserve_order")]
13use alloc::vec::Vec;
14use core::borrow::Borrow;
15use core::fmt::{self, Debug};
16use core::hash::{Hash, Hasher};
17use core::iter::FusedIterator;
18#[cfg(feature = "preserve_order")]
19use core::mem;
20use core::ops;
21use serde::de;
22
23#[cfg(not(feature = "preserve_order"))]
24use alloc::collections::{btree_map, BTreeMap};
25#[cfg(feature = "preserve_order")]
26use indexmap::IndexMap;
27
28pub struct Map<K, V> {
30 map: MapImpl<K, V>,
31}
32
33#[cfg(not(feature = "preserve_order"))]
34type MapImpl<K, V> = BTreeMap<K, V>;
35#[cfg(feature = "preserve_order")]
36type MapImpl<K, V> = IndexMap<K, V>;
37
38impl Map<String, Value> {
39 #[inline]
41 pub fn new() -> Self {
42 Map {
43 map: MapImpl::new(),
44 }
45 }
46
47 #[inline]
49 pub fn with_capacity(capacity: usize) -> Self {
50 Map {
51 #[cfg(not(feature = "preserve_order"))]
52 map: {
53 let _ = capacity;
55 BTreeMap::new()
56 },
57 #[cfg(feature = "preserve_order")]
58 map: IndexMap::with_capacity(capacity),
59 }
60 }
61
62 #[inline]
64 pub fn clear(&mut self) {
65 self.map.clear();
66 }
67
68 #[inline]
73 pub fn get<Q>(&self, key: &Q) -> Option<&Value>
74 where
75 String: Borrow<Q>,
76 Q: ?Sized + Ord + Eq + Hash,
77 {
78 self.map.get(key)
79 }
80
81 #[inline]
86 pub fn contains_key<Q>(&self, key: &Q) -> bool
87 where
88 String: Borrow<Q>,
89 Q: ?Sized + Ord + Eq + Hash,
90 {
91 self.map.contains_key(key)
92 }
93
94 #[inline]
99 pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
100 where
101 String: Borrow<Q>,
102 Q: ?Sized + Ord + Eq + Hash,
103 {
104 self.map.get_mut(key)
105 }
106
107 #[inline]
112 pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
113 where
114 String: Borrow<Q>,
115 Q: ?Sized + Ord + Eq + Hash,
116 {
117 self.map.get_key_value(key)
118 }
119
120 #[inline]
127 pub fn insert(&mut self, k: String, v: Value) -> Option<Value> {
128 self.map.insert(k, v)
129 }
130
131 #[cfg(feature = "preserve_order")]
138 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
139 #[inline]
140 pub fn shift_insert(&mut self, index: usize, k: String, v: Value) -> Option<Value> {
141 self.map.shift_insert(index, k, v)
142 }
143
144 #[inline]
156 pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
157 where
158 String: Borrow<Q>,
159 Q: ?Sized + Ord + Eq + Hash,
160 {
161 #[cfg(feature = "preserve_order")]
162 return self.swap_remove(key);
163 #[cfg(not(feature = "preserve_order"))]
164 return self.map.remove(key);
165 }
166
167 #[inline]
179 pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
180 where
181 String: Borrow<Q>,
182 Q: ?Sized + Ord + Eq + Hash,
183 {
184 #[cfg(feature = "preserve_order")]
185 return self.swap_remove_entry(key);
186 #[cfg(not(feature = "preserve_order"))]
187 return self.map.remove_entry(key);
188 }
189
190 #[cfg(feature = "preserve_order")]
198 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
199 #[inline]
200 pub fn swap_remove<Q>(&mut self, key: &Q) -> Option<Value>
201 where
202 String: Borrow<Q>,
203 Q: ?Sized + Ord + Eq + Hash,
204 {
205 self.map.swap_remove(key)
206 }
207
208 #[cfg(feature = "preserve_order")]
216 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
217 #[inline]
218 pub fn swap_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
219 where
220 String: Borrow<Q>,
221 Q: ?Sized + Ord + Eq + Hash,
222 {
223 self.map.swap_remove_entry(key)
224 }
225
226 #[cfg(feature = "preserve_order")]
234 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
235 #[inline]
236 pub fn shift_remove<Q>(&mut self, key: &Q) -> Option<Value>
237 where
238 String: Borrow<Q>,
239 Q: ?Sized + Ord + Eq + Hash,
240 {
241 self.map.shift_remove(key)
242 }
243
244 #[cfg(feature = "preserve_order")]
252 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
253 #[inline]
254 pub fn shift_remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
255 where
256 String: Borrow<Q>,
257 Q: ?Sized + Ord + Eq + Hash,
258 {
259 self.map.shift_remove_entry(key)
260 }
261
262 #[inline]
264 pub fn append(&mut self, other: &mut Self) {
265 #[cfg(feature = "preserve_order")]
266 self.map
267 .extend(mem::replace(&mut other.map, MapImpl::default()));
268 #[cfg(not(feature = "preserve_order"))]
269 self.map.append(&mut other.map);
270 }
271
272 pub fn entry<S>(&mut self, key: S) -> Entry
275 where
276 S: Into<String>,
277 {
278 #[cfg(not(feature = "preserve_order"))]
279 use alloc::collections::btree_map::Entry as EntryImpl;
280 #[cfg(feature = "preserve_order")]
281 use indexmap::map::Entry as EntryImpl;
282
283 match self.map.entry(key.into()) {
284 EntryImpl::Vacant(vacant) => Entry::Vacant(VacantEntry { vacant }),
285 EntryImpl::Occupied(occupied) => Entry::Occupied(OccupiedEntry { occupied }),
286 }
287 }
288
289 #[inline]
291 pub fn len(&self) -> usize {
292 self.map.len()
293 }
294
295 #[inline]
297 pub fn is_empty(&self) -> bool {
298 self.map.is_empty()
299 }
300
301 #[inline]
303 pub fn iter(&self) -> Iter {
304 Iter {
305 iter: self.map.iter(),
306 }
307 }
308
309 #[inline]
311 pub fn iter_mut(&mut self) -> IterMut {
312 IterMut {
313 iter: self.map.iter_mut(),
314 }
315 }
316
317 #[inline]
319 pub fn keys(&self) -> Keys {
320 Keys {
321 iter: self.map.keys(),
322 }
323 }
324
325 #[inline]
327 pub fn values(&self) -> Values {
328 Values {
329 iter: self.map.values(),
330 }
331 }
332
333 #[inline]
335 pub fn values_mut(&mut self) -> ValuesMut {
336 ValuesMut {
337 iter: self.map.values_mut(),
338 }
339 }
340
341 #[inline]
343 pub fn into_values(self) -> IntoValues {
344 IntoValues {
345 iter: self.map.into_values(),
346 }
347 }
348
349 #[inline]
354 pub fn retain<F>(&mut self, f: F)
355 where
356 F: FnMut(&String, &mut Value) -> bool,
357 {
358 self.map.retain(f);
359 }
360
361 #[inline]
379 pub fn sort_keys(&mut self) {
380 #[cfg(feature = "preserve_order")]
381 self.map.sort_unstable_keys();
382 }
383}
384
385#[allow(clippy::derivable_impls)] impl Default for Map<String, Value> {
387 #[inline]
388 fn default() -> Self {
389 Map {
390 map: MapImpl::new(),
391 }
392 }
393}
394
395impl Clone for Map<String, Value> {
396 #[inline]
397 fn clone(&self) -> Self {
398 Map {
399 map: self.map.clone(),
400 }
401 }
402
403 #[inline]
404 fn clone_from(&mut self, source: &Self) {
405 self.map.clone_from(&source.map);
406 }
407}
408
409impl PartialEq for Map<String, Value> {
410 #[inline]
411 fn eq(&self, other: &Self) -> bool {
412 self.map.eq(&other.map)
413 }
414}
415
416impl Eq for Map<String, Value> {}
417
418impl Hash for Map<String, Value> {
419 fn hash<H: Hasher>(&self, state: &mut H) {
420 #[cfg(not(feature = "preserve_order"))]
421 {
422 self.map.hash(state);
423 }
424
425 #[cfg(feature = "preserve_order")]
426 {
427 let mut kv = Vec::from_iter(&self.map);
428 kv.sort_unstable_by(|a, b| a.0.cmp(b.0));
429 kv.hash(state);
430 }
431 }
432}
433
434impl<Q> ops::Index<&Q> for Map<String, Value>
451where
452 String: Borrow<Q>,
453 Q: ?Sized + Ord + Eq + Hash,
454{
455 type Output = Value;
456
457 fn index(&self, index: &Q) -> &Value {
458 self.map.index(index)
459 }
460}
461
462impl<Q> ops::IndexMut<&Q> for Map<String, Value>
474where
475 String: Borrow<Q>,
476 Q: ?Sized + Ord + Eq + Hash,
477{
478 fn index_mut(&mut self, index: &Q) -> &mut Value {
479 self.map.get_mut(index).expect("no entry found for key")
480 }
481}
482
483impl Debug for Map<String, Value> {
484 #[inline]
485 fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
486 self.map.fmt(formatter)
487 }
488}
489
490#[cfg(any(feature = "std", feature = "alloc"))]
491impl serde::ser::Serialize for Map<String, Value> {
492 #[inline]
493 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
494 where
495 S: serde::ser::Serializer,
496 {
497 use serde::ser::SerializeMap;
498 let mut map = match serializer.serialize_map(Some(self.len())) {
core::result::Result::Ok(val) => val,
core::result::Result::Err(err) => return core::result::Result::Err(err),
}tri!(serializer.serialize_map(Some(self.len())));
499 for (k, v) in self {
500 match map.serialize_entry(k, v) {
core::result::Result::Ok(val) => val,
core::result::Result::Err(err) => return core::result::Result::Err(err),
};tri!(map.serialize_entry(k, v));
501 }
502 map.end()
503 }
504}
505
506impl<'de> de::Deserialize<'de> for Map<String, Value> {
507 #[inline]
508 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
509 where
510 D: de::Deserializer<'de>,
511 {
512 struct Visitor;
513
514 impl<'de> de::Visitor<'de> for Visitor {
515 type Value = Map<String, Value>;
516
517 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
518 formatter.write_str("a map")
519 }
520
521 #[inline]
522 fn visit_unit<E>(self) -> Result<Self::Value, E>
523 where
524 E: de::Error,
525 {
526 Ok(Map::new())
527 }
528
529 #[cfg(any(feature = "std", feature = "alloc"))]
530 #[inline]
531 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
532 where
533 V: de::MapAccess<'de>,
534 {
535 let mut values = Map::new();
536
537 while let Some((key, value)) = match visitor.next_entry() {
core::result::Result::Ok(val) => val,
core::result::Result::Err(err) => return core::result::Result::Err(err),
}tri!(visitor.next_entry()) {
538 values.insert(key, value);
539 }
540
541 Ok(values)
542 }
543 }
544
545 deserializer.deserialize_map(Visitor)
546 }
547}
548
549impl FromIterator<(String, Value)> for Map<String, Value> {
550 fn from_iter<T>(iter: T) -> Self
551 where
552 T: IntoIterator<Item = (String, Value)>,
553 {
554 Map {
555 map: FromIterator::from_iter(iter),
556 }
557 }
558}
559
560impl Extend<(String, Value)> for Map<String, Value> {
561 fn extend<T>(&mut self, iter: T)
562 where
563 T: IntoIterator<Item = (String, Value)>,
564 {
565 self.map.extend(iter);
566 }
567}
568
569macro_rules! delegate_iterator {
570 (($name:ident $($generics:tt)*) => $item:ty) => {
571 impl $($generics)* Iterator for $name $($generics)* {
572 type Item = $item;
573 #[inline]
574 fn next(&mut self) -> Option<Self::Item> {
575 self.iter.next()
576 }
577 #[inline]
578 fn size_hint(&self) -> (usize, Option<usize>) {
579 self.iter.size_hint()
580 }
581 }
582
583 impl $($generics)* DoubleEndedIterator for $name $($generics)* {
584 #[inline]
585 fn next_back(&mut self) -> Option<Self::Item> {
586 self.iter.next_back()
587 }
588 }
589
590 impl $($generics)* ExactSizeIterator for $name $($generics)* {
591 #[inline]
592 fn len(&self) -> usize {
593 self.iter.len()
594 }
595 }
596
597 impl $($generics)* FusedIterator for $name $($generics)* {}
598 }
599}
600
601impl<'de> de::IntoDeserializer<'de, Error> for Map<String, Value> {
602 type Deserializer = Self;
603
604 fn into_deserializer(self) -> Self::Deserializer {
605 self
606 }
607}
608
609impl<'de> de::IntoDeserializer<'de, Error> for &'de Map<String, Value> {
610 type Deserializer = Self;
611
612 fn into_deserializer(self) -> Self::Deserializer {
613 self
614 }
615}
616
617pub enum Entry<'a> {
624 Vacant(VacantEntry<'a>),
626 Occupied(OccupiedEntry<'a>),
628}
629
630pub struct VacantEntry<'a> {
632 vacant: VacantEntryImpl<'a>,
633}
634
635pub struct OccupiedEntry<'a> {
637 occupied: OccupiedEntryImpl<'a>,
638}
639
640#[cfg(not(feature = "preserve_order"))]
641type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
642#[cfg(feature = "preserve_order")]
643type VacantEntryImpl<'a> = indexmap::map::VacantEntry<'a, String, Value>;
644
645#[cfg(not(feature = "preserve_order"))]
646type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
647#[cfg(feature = "preserve_order")]
648type OccupiedEntryImpl<'a> = indexmap::map::OccupiedEntry<'a, String, Value>;
649
650impl<'a> Entry<'a> {
651 pub fn key(&self) -> &String {
660 match self {
661 Entry::Vacant(e) => e.key(),
662 Entry::Occupied(e) => e.key(),
663 }
664 }
665
666 pub fn or_insert(self, default: Value) -> &'a mut Value {
680 match self {
681 Entry::Vacant(entry) => entry.insert(default),
682 Entry::Occupied(entry) => entry.into_mut(),
683 }
684 }
685
686 pub fn or_insert_with<F>(self, default: F) -> &'a mut Value
701 where
702 F: FnOnce() -> Value,
703 {
704 match self {
705 Entry::Vacant(entry) => entry.insert(default()),
706 Entry::Occupied(entry) => entry.into_mut(),
707 }
708 }
709
710 pub fn and_modify<F>(self, f: F) -> Self
732 where
733 F: FnOnce(&mut Value),
734 {
735 match self {
736 Entry::Occupied(mut entry) => {
737 f(entry.get_mut());
738 Entry::Occupied(entry)
739 }
740 Entry::Vacant(entry) => Entry::Vacant(entry),
741 }
742 }
743}
744
745impl<'a> VacantEntry<'a> {
746 #[inline]
764 pub fn key(&self) -> &String {
765 self.vacant.key()
766 }
767
768 #[inline]
788 pub fn insert(self, value: Value) -> &'a mut Value {
789 self.vacant.insert(value)
790 }
791}
792
793impl<'a> OccupiedEntry<'a> {
794 #[inline]
814 pub fn key(&self) -> &String {
815 self.occupied.key()
816 }
817
818 #[inline]
838 pub fn get(&self) -> &Value {
839 self.occupied.get()
840 }
841
842 #[inline]
864 pub fn get_mut(&mut self) -> &mut Value {
865 self.occupied.get_mut()
866 }
867
868 #[inline]
890 pub fn into_mut(self) -> &'a mut Value {
891 self.occupied.into_mut()
892 }
893
894 #[inline]
916 pub fn insert(&mut self, value: Value) -> Value {
917 self.occupied.insert(value)
918 }
919
920 #[inline]
946 pub fn remove(self) -> Value {
947 #[cfg(feature = "preserve_order")]
948 return self.swap_remove();
949 #[cfg(not(feature = "preserve_order"))]
950 return self.occupied.remove();
951 }
952
953 #[cfg(feature = "preserve_order")]
961 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
962 #[inline]
963 pub fn swap_remove(self) -> Value {
964 self.occupied.swap_remove()
965 }
966
967 #[cfg(feature = "preserve_order")]
975 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
976 #[inline]
977 pub fn shift_remove(self) -> Value {
978 self.occupied.shift_remove()
979 }
980
981 #[inline]
1009 pub fn remove_entry(self) -> (String, Value) {
1010 #[cfg(feature = "preserve_order")]
1011 return self.swap_remove_entry();
1012 #[cfg(not(feature = "preserve_order"))]
1013 return self.occupied.remove_entry();
1014 }
1015
1016 #[cfg(feature = "preserve_order")]
1024 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
1025 #[inline]
1026 pub fn swap_remove_entry(self) -> (String, Value) {
1027 self.occupied.swap_remove_entry()
1028 }
1029
1030 #[cfg(feature = "preserve_order")]
1038 #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
1039 #[inline]
1040 pub fn shift_remove_entry(self) -> (String, Value) {
1041 self.occupied.shift_remove_entry()
1042 }
1043}
1044
1045impl<'a> IntoIterator for &'a Map<String, Value> {
1048 type Item = (&'a String, &'a Value);
1049 type IntoIter = Iter<'a>;
1050 #[inline]
1051 fn into_iter(self) -> Self::IntoIter {
1052 Iter {
1053 iter: self.map.iter(),
1054 }
1055 }
1056}
1057
1058)]
1060pub struct Iter<'a> {
1061 iter: IterImpl<'a>,
1062}
1063
1064#[cfg(not(feature = "preserve_order"))]
1065type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
1066#[cfg(feature = "preserve_order")]
1067type IterImpl<'a> = indexmap::map::Iter<'a, String, Value>;
1068
1069impl<'a> Iterator for Iter<'a> {
type Item = (&'a String, &'a Value);
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl<'a> DoubleEndedIterator for Iter<'a> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl<'a> ExactSizeIterator for Iter<'a> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl<'a> FusedIterator for Iter<'a> {}delegate_iterator!((Iter<'a>) => (&'a String, &'a Value));
1070
1071impl<'a> IntoIterator for &'a mut Map<String, Value> {
1074 type Item = (&'a String, &'a mut Value);
1075 type IntoIter = IterMut<'a>;
1076 #[inline]
1077 fn into_iter(self) -> Self::IntoIter {
1078 IterMut {
1079 iter: self.map.iter_mut(),
1080 }
1081 }
1082}
1083
1084)]
1086pub struct IterMut<'a> {
1087 iter: IterMutImpl<'a>,
1088}
1089
1090#[cfg(not(feature = "preserve_order"))]
1091type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
1092#[cfg(feature = "preserve_order")]
1093type IterMutImpl<'a> = indexmap::map::IterMut<'a, String, Value>;
1094
1095impl<'a> Iterator for IterMut<'a> {
type Item = (&'a String, &'a mut Value);
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl<'a> DoubleEndedIterator for IterMut<'a> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl<'a> ExactSizeIterator for IterMut<'a> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl<'a> FusedIterator for IterMut<'a> {}delegate_iterator!((IterMut<'a>) => (&'a String, &'a mut Value));
1096
1097impl IntoIterator for Map<String, Value> {
1100 type Item = (String, Value);
1101 type IntoIter = IntoIter;
1102 #[inline]
1103 fn into_iter(self) -> Self::IntoIter {
1104 IntoIter {
1105 iter: self.map.into_iter(),
1106 }
1107 }
1108}
1109
1110)]
1112pub struct IntoIter {
1113 iter: IntoIterImpl,
1114}
1115
1116#[cfg(not(feature = "preserve_order"))]
1117type IntoIterImpl = btree_map::IntoIter<String, Value>;
1118#[cfg(feature = "preserve_order")]
1119type IntoIterImpl = indexmap::map::IntoIter<String, Value>;
1120
1121impl Iterator for IntoIter {
type Item = (String, Value);
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl DoubleEndedIterator for IntoIter {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl ExactSizeIterator for IntoIter {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl FusedIterator for IntoIter {}delegate_iterator!((IntoIter) => (String, Value));
1122
1123)]
1127pub struct Keys<'a> {
1128 iter: KeysImpl<'a>,
1129}
1130
1131#[cfg(not(feature = "preserve_order"))]
1132type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
1133#[cfg(feature = "preserve_order")]
1134type KeysImpl<'a> = indexmap::map::Keys<'a, String, Value>;
1135
1136impl<'a> Iterator for Keys<'a> {
type Item = &'a String;
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl<'a> DoubleEndedIterator for Keys<'a> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl<'a> ExactSizeIterator for Keys<'a> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl<'a> FusedIterator for Keys<'a> {}delegate_iterator!((Keys<'a>) => &'a String);
1137
1138)]
1142pub struct Values<'a> {
1143 iter: ValuesImpl<'a>,
1144}
1145
1146#[cfg(not(feature = "preserve_order"))]
1147type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
1148#[cfg(feature = "preserve_order")]
1149type ValuesImpl<'a> = indexmap::map::Values<'a, String, Value>;
1150
1151impl<'a> Iterator for Values<'a> {
type Item = &'a Value;
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl<'a> DoubleEndedIterator for Values<'a> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl<'a> ExactSizeIterator for Values<'a> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl<'a> FusedIterator for Values<'a> {}delegate_iterator!((Values<'a>) => &'a Value);
1152
1153)]
1157pub struct ValuesMut<'a> {
1158 iter: ValuesMutImpl<'a>,
1159}
1160
1161#[cfg(not(feature = "preserve_order"))]
1162type ValuesMutImpl<'a> = btree_map::ValuesMut<'a, String, Value>;
1163#[cfg(feature = "preserve_order")]
1164type ValuesMutImpl<'a> = indexmap::map::ValuesMut<'a, String, Value>;
1165
1166impl<'a> Iterator for ValuesMut<'a> {
type Item = &'a mut Value;
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl<'a> DoubleEndedIterator for ValuesMut<'a> {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl<'a> ExactSizeIterator for ValuesMut<'a> {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl<'a> FusedIterator for ValuesMut<'a> {}delegate_iterator!((ValuesMut<'a>) => &'a mut Value);
1167
1168)]
1172pub struct IntoValues {
1173 iter: IntoValuesImpl,
1174}
1175
1176#[cfg(not(feature = "preserve_order"))]
1177type IntoValuesImpl = btree_map::IntoValues<String, Value>;
1178#[cfg(feature = "preserve_order")]
1179type IntoValuesImpl = indexmap::map::IntoValues<String, Value>;
1180
1181impl Iterator for IntoValues {
type Item = Value;
#[inline]
fn next(&mut self) -> Option<Self::Item> { self.iter.next() }
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
}
impl DoubleEndedIterator for IntoValues {
#[inline]
fn next_back(&mut self) -> Option<Self::Item> { self.iter.next_back() }
}
impl ExactSizeIterator for IntoValues {
#[inline]
fn len(&self) -> usize { self.iter.len() }
}
impl FusedIterator for IntoValues {}delegate_iterator!((IntoValues) => Value);