serde_json/map.rs
1//! A map of String to serde_json::Value.
2//!
3//! By default the map is backed by a [`BTreeMap`]. Enable the `preserve_order`
4//! feature of serde_json to use [`IndexMap`] instead.
5//!
6//! [`BTreeMap`]: https://doc.rust-lang.org/std/collections/struct.BTreeMap.html
7//! [`IndexMap`]: https://docs.rs/indexmap/*/indexmap/map/struct.IndexMap.html
8
9use serde::{de, ser};
10use std::borrow::Borrow;
11use std::fmt::{self, Debug};
12use std::hash::Hash;
13use std::iter::FromIterator;
14use std::ops;
15use value::Value;
16
17#[cfg(not(feature = "preserve_order"))]
18use std::collections::{btree_map, BTreeMap};
19
20#[cfg(feature = "preserve_order")]
21use indexmap::{self, IndexMap};
22
23/// Represents a JSON key/value type.
24pub struct Map<K, V> {
25 map: MapImpl<K, V>,
26}
27
28#[cfg(not(feature = "preserve_order"))]
29type MapImpl<K, V> = BTreeMap<K, V>;
30#[cfg(feature = "preserve_order")]
31type MapImpl<K, V> = IndexMap<K, V>;
32
33impl Map<String, Value> {
34 /// Makes a new empty Map.
35 #[inline]
36 pub fn new() -> Self {
37 Map {
38 map: MapImpl::new(),
39 }
40 }
41
42 #[cfg(not(feature = "preserve_order"))]
43 /// Makes a new empty Map with the given initial capacity.
44 #[inline]
45 pub fn with_capacity(capacity: usize) -> Self {
46 // does not support with_capacity
47 let _ = capacity;
48 Map {
49 map: BTreeMap::new(),
50 }
51 }
52
53 #[cfg(feature = "preserve_order")]
54 /// Makes a new empty Map with the given initial capacity.
55 #[inline]
56 pub fn with_capacity(capacity: usize) -> Self {
57 Map {
58 map: IndexMap::with_capacity(capacity),
59 }
60 }
61
62 /// Clears the map, removing all values.
63 #[inline]
64 pub fn clear(&mut self) {
65 self.map.clear()
66 }
67
68 /// Returns a reference to the value corresponding to the key.
69 ///
70 /// The key may be any borrowed form of the map's key type, but the ordering
71 /// on the borrowed form *must* match the ordering on the key type.
72 #[inline]
73 pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&Value>
74 where
75 String: Borrow<Q>,
76 Q: Ord + Eq + Hash,
77 {
78 self.map.get(key)
79 }
80
81 /// Returns true if the map contains a value for the specified key.
82 ///
83 /// The key may be any borrowed form of the map's key type, but the ordering
84 /// on the borrowed form *must* match the ordering on the key type.
85 #[inline]
86 pub fn contains_key<Q: ?Sized>(&self, key: &Q) -> bool
87 where
88 String: Borrow<Q>,
89 Q: Ord + Eq + Hash,
90 {
91 self.map.contains_key(key)
92 }
93
94 /// Returns a mutable reference to the value corresponding to the key.
95 ///
96 /// The key may be any borrowed form of the map's key type, but the ordering
97 /// on the borrowed form *must* match the ordering on the key type.
98 #[inline]
99 pub fn get_mut<Q: ?Sized>(&mut self, key: &Q) -> Option<&mut Value>
100 where
101 String: Borrow<Q>,
102 Q: Ord + Eq + Hash,
103 {
104 self.map.get_mut(key)
105 }
106
107 /// Inserts a key-value pair into the map.
108 ///
109 /// If the map did not have this key present, `None` is returned.
110 ///
111 /// If the map did have this key present, the value is updated, and the old
112 /// value is returned.
113 #[inline]
114 pub fn insert(&mut self, k: String, v: Value) -> Option<Value> {
115 self.map.insert(k, v)
116 }
117
118 /// Removes a key from the map, returning the value at the key if the key
119 /// was previously in the map.
120 ///
121 /// The key may be any borrowed form of the map's key type, but the ordering
122 /// on the borrowed form *must* match the ordering on the key type.
123 #[inline]
124 pub fn remove<Q: ?Sized>(&mut self, key: &Q) -> Option<Value>
125 where
126 String: Borrow<Q>,
127 Q: Ord + Eq + Hash,
128 {
129 #[cfg(feature = "preserve_order")]
130 return self.map.swap_remove(key);
131 #[cfg(not(feature = "preserve_order"))]
132 return self.map.remove(key);
133 }
134
135 /// Gets the given key's corresponding entry in the map for in-place
136 /// manipulation.
137 pub fn entry<S>(&mut self, key: S) -> Entry
138 where
139 S: Into<String>,
140 {
141 #[cfg(feature = "preserve_order")]
142 use indexmap::map::Entry as EntryImpl;
143 #[cfg(not(feature = "preserve_order"))]
144 use std::collections::btree_map::Entry as EntryImpl;
145
146 match self.map.entry(key.into()) {
147 EntryImpl::Vacant(vacant) => Entry::Vacant(VacantEntry { vacant: vacant }),
148 EntryImpl::Occupied(occupied) => Entry::Occupied(OccupiedEntry { occupied: occupied }),
149 }
150 }
151
152 /// Returns the number of elements in the map.
153 #[inline]
154 pub fn len(&self) -> usize {
155 self.map.len()
156 }
157
158 /// Returns true if the map contains no elements.
159 #[inline]
160 pub fn is_empty(&self) -> bool {
161 self.map.is_empty()
162 }
163
164 /// Gets an iterator over the entries of the map.
165 #[inline]
166 pub fn iter(&self) -> Iter {
167 Iter {
168 iter: self.map.iter(),
169 }
170 }
171
172 /// Gets a mutable iterator over the entries of the map.
173 #[inline]
174 pub fn iter_mut(&mut self) -> IterMut {
175 IterMut {
176 iter: self.map.iter_mut(),
177 }
178 }
179
180 /// Gets an iterator over the keys of the map.
181 #[inline]
182 pub fn keys(&self) -> Keys {
183 Keys {
184 iter: self.map.keys(),
185 }
186 }
187
188 /// Gets an iterator over the values of the map.
189 #[inline]
190 pub fn values(&self) -> Values {
191 Values {
192 iter: self.map.values(),
193 }
194 }
195
196 /// Gets an iterator over mutable values of the map.
197 #[inline]
198 pub fn values_mut(&mut self) -> ValuesMut {
199 ValuesMut {
200 iter: self.map.values_mut(),
201 }
202 }
203}
204
205impl Default for Map<String, Value> {
206 #[inline]
207 fn default() -> Self {
208 Map {
209 map: MapImpl::new(),
210 }
211 }
212}
213
214impl Clone for Map<String, Value> {
215 #[inline]
216 fn clone(&self) -> Self {
217 Map {
218 map: self.map.clone(),
219 }
220 }
221}
222
223impl PartialEq for Map<String, Value> {
224 #[inline]
225 fn eq(&self, other: &Self) -> bool {
226 if cfg!(feature = "preserve_order") {
227 if self.len() != other.len() {
228 return false;
229 }
230
231 self.iter()
232 .all(|(key, value)| other.get(key).map_or(false, |v| *value == *v))
233 } else {
234 self.map.eq(&other.map)
235 }
236 }
237}
238
239/// Access an element of this map. Panics if the given key is not present in the
240/// map.
241///
242/// ```edition2018
243/// # use serde_json::Value;
244/// #
245/// # let val = &Value::String("".to_owned());
246/// # let _ =
247/// match *val {
248/// Value::String(ref s) => Some(s.as_str()),
249/// Value::Array(ref arr) => arr[0].as_str(),
250/// Value::Object(ref map) => map["type"].as_str(),
251/// _ => None,
252/// }
253/// # ;
254/// ```
255impl<'a, Q: ?Sized> ops::Index<&'a Q> for Map<String, Value>
256where
257 String: Borrow<Q>,
258 Q: Ord + Eq + Hash,
259{
260 type Output = Value;
261
262 fn index(&self, index: &Q) -> &Value {
263 self.map.index(index)
264 }
265}
266
267/// Mutably access an element of this map. Panics if the given key is not
268/// present in the map.
269///
270/// ```edition2018
271/// # use serde_json::json;
272/// #
273/// # let mut map = serde_json::Map::new();
274/// # map.insert("key".to_owned(), serde_json::Value::Null);
275/// #
276/// map["key"] = json!("value");
277/// ```
278impl<'a, Q: ?Sized> ops::IndexMut<&'a Q> for Map<String, Value>
279where
280 String: Borrow<Q>,
281 Q: Ord + Eq + Hash,
282{
283 fn index_mut(&mut self, index: &Q) -> &mut Value {
284 self.map.get_mut(index).expect("no entry found for key")
285 }
286}
287
288impl Debug for Map<String, Value> {
289 #[inline]
290 fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
291 self.map.fmt(formatter)
292 }
293}
294
295impl ser::Serialize for Map<String, Value> {
296 #[inline]
297 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
298 where
299 S: ser::Serializer,
300 {
301 use serde::ser::SerializeMap;
302 let mut map = try!(serializer.serialize_map(Some(self.len())));
303 for (k, v) in self {
304 try!(map.serialize_key(k));
305 try!(map.serialize_value(v));
306 }
307 map.end()
308 }
309}
310
311impl<'de> de::Deserialize<'de> for Map<String, Value> {
312 #[inline]
313 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
314 where
315 D: de::Deserializer<'de>,
316 {
317 struct Visitor;
318
319 impl<'de> de::Visitor<'de> for Visitor {
320 type Value = Map<String, Value>;
321
322 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
323 formatter.write_str("a map")
324 }
325
326 #[inline]
327 fn visit_unit<E>(self) -> Result<Self::Value, E>
328 where
329 E: de::Error,
330 {
331 Ok(Map::new())
332 }
333
334 #[inline]
335 fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
336 where
337 V: de::MapAccess<'de>,
338 {
339 let mut values = Map::new();
340
341 while let Some((key, value)) = try!(visitor.next_entry()) {
342 values.insert(key, value);
343 }
344
345 Ok(values)
346 }
347 }
348
349 deserializer.deserialize_map(Visitor)
350 }
351}
352
353impl FromIterator<(String, Value)> for Map<String, Value> {
354 fn from_iter<T>(iter: T) -> Self
355 where
356 T: IntoIterator<Item = (String, Value)>,
357 {
358 Map {
359 map: FromIterator::from_iter(iter),
360 }
361 }
362}
363
364impl Extend<(String, Value)> for Map<String, Value> {
365 fn extend<T>(&mut self, iter: T)
366 where
367 T: IntoIterator<Item = (String, Value)>,
368 {
369 self.map.extend(iter);
370 }
371}
372
373macro_rules! delegate_iterator {
374 (($name:ident $($generics:tt)*) => $item:ty) => {
375 impl $($generics)* Iterator for $name $($generics)* {
376 type Item = $item;
377 #[inline]
378 fn next(&mut self) -> Option<Self::Item> {
379 self.iter.next()
380 }
381 #[inline]
382 fn size_hint(&self) -> (usize, Option<usize>) {
383 self.iter.size_hint()
384 }
385 }
386
387 impl $($generics)* DoubleEndedIterator for $name $($generics)* {
388 #[inline]
389 fn next_back(&mut self) -> Option<Self::Item> {
390 self.iter.next_back()
391 }
392 }
393
394 impl $($generics)* ExactSizeIterator for $name $($generics)* {
395 #[inline]
396 fn len(&self) -> usize {
397 self.iter.len()
398 }
399 }
400 }
401}
402
403//////////////////////////////////////////////////////////////////////////////
404
405/// A view into a single entry in a map, which may either be vacant or occupied.
406/// This enum is constructed from the [`entry`] method on [`Map`].
407///
408/// [`entry`]: struct.Map.html#method.entry
409/// [`Map`]: struct.Map.html
410pub enum Entry<'a> {
411 /// A vacant Entry.
412 Vacant(VacantEntry<'a>),
413 /// An occupied Entry.
414 Occupied(OccupiedEntry<'a>),
415}
416
417/// A vacant Entry. It is part of the [`Entry`] enum.
418///
419/// [`Entry`]: enum.Entry.html
420pub struct VacantEntry<'a> {
421 vacant: VacantEntryImpl<'a>,
422}
423
424/// An occupied Entry. It is part of the [`Entry`] enum.
425///
426/// [`Entry`]: enum.Entry.html
427pub struct OccupiedEntry<'a> {
428 occupied: OccupiedEntryImpl<'a>,
429}
430
431#[cfg(not(feature = "preserve_order"))]
432type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
433#[cfg(feature = "preserve_order")]
434type VacantEntryImpl<'a> = indexmap::map::VacantEntry<'a, String, Value>;
435
436#[cfg(not(feature = "preserve_order"))]
437type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
438#[cfg(feature = "preserve_order")]
439type OccupiedEntryImpl<'a> = indexmap::map::OccupiedEntry<'a, String, Value>;
440
441impl<'a> Entry<'a> {
442 /// Returns a reference to this entry's key.
443 ///
444 /// # Examples
445 ///
446 /// ```edition2018
447 /// let mut map = serde_json::Map::new();
448 /// assert_eq!(map.entry("serde").key(), &"serde");
449 /// ```
450 pub fn key(&self) -> &String {
451 match *self {
452 Entry::Vacant(ref e) => e.key(),
453 Entry::Occupied(ref e) => e.key(),
454 }
455 }
456
457 /// Ensures a value is in the entry by inserting the default if empty, and
458 /// returns a mutable reference to the value in the entry.
459 ///
460 /// # Examples
461 ///
462 /// ```edition2018
463 /// # use serde_json::json;
464 /// #
465 /// let mut map = serde_json::Map::new();
466 /// map.entry("serde").or_insert(json!(12));
467 ///
468 /// assert_eq!(map["serde"], 12);
469 /// ```
470 pub fn or_insert(self, default: Value) -> &'a mut Value {
471 match self {
472 Entry::Vacant(entry) => entry.insert(default),
473 Entry::Occupied(entry) => entry.into_mut(),
474 }
475 }
476
477 /// Ensures a value is in the entry by inserting the result of the default
478 /// function if empty, and returns a mutable reference to the value in the
479 /// entry.
480 ///
481 /// # Examples
482 ///
483 /// ```edition2018
484 /// # use serde_json::json;
485 /// #
486 /// let mut map = serde_json::Map::new();
487 /// map.entry("serde").or_insert_with(|| json!("hoho"));
488 ///
489 /// assert_eq!(map["serde"], "hoho".to_owned());
490 /// ```
491 pub fn or_insert_with<F>(self, default: F) -> &'a mut Value
492 where
493 F: FnOnce() -> Value,
494 {
495 match self {
496 Entry::Vacant(entry) => entry.insert(default()),
497 Entry::Occupied(entry) => entry.into_mut(),
498 }
499 }
500}
501
502impl<'a> VacantEntry<'a> {
503 /// Gets a reference to the key that would be used when inserting a value
504 /// through the VacantEntry.
505 ///
506 /// # Examples
507 ///
508 /// ```edition2018
509 /// use serde_json::map::Entry;
510 ///
511 /// let mut map = serde_json::Map::new();
512 ///
513 /// match map.entry("serde") {
514 /// Entry::Vacant(vacant) => {
515 /// assert_eq!(vacant.key(), &"serde");
516 /// }
517 /// Entry::Occupied(_) => unimplemented!(),
518 /// }
519 /// ```
520 #[inline]
521 pub fn key(&self) -> &String {
522 self.vacant.key()
523 }
524
525 /// Sets the value of the entry with the VacantEntry's key, and returns a
526 /// mutable reference to it.
527 ///
528 /// # Examples
529 ///
530 /// ```edition2018
531 /// # use serde_json::json;
532 /// #
533 /// use serde_json::map::Entry;
534 ///
535 /// let mut map = serde_json::Map::new();
536 ///
537 /// match map.entry("serde") {
538 /// Entry::Vacant(vacant) => {
539 /// vacant.insert(json!("hoho"));
540 /// }
541 /// Entry::Occupied(_) => unimplemented!(),
542 /// }
543 /// ```
544 #[inline]
545 pub fn insert(self, value: Value) -> &'a mut Value {
546 self.vacant.insert(value)
547 }
548}
549
550impl<'a> OccupiedEntry<'a> {
551 /// Gets a reference to the key in the entry.
552 ///
553 /// # Examples
554 ///
555 /// ```edition2018
556 /// # use serde_json::json;
557 /// #
558 /// use serde_json::map::Entry;
559 ///
560 /// let mut map = serde_json::Map::new();
561 /// map.insert("serde".to_owned(), json!(12));
562 ///
563 /// match map.entry("serde") {
564 /// Entry::Occupied(occupied) => {
565 /// assert_eq!(occupied.key(), &"serde");
566 /// }
567 /// Entry::Vacant(_) => unimplemented!(),
568 /// }
569 /// ```
570 #[inline]
571 pub fn key(&self) -> &String {
572 self.occupied.key()
573 }
574
575 /// Gets a reference to the value in the entry.
576 ///
577 /// # Examples
578 ///
579 /// ```edition2018
580 /// # use serde_json::json;
581 /// #
582 /// use serde_json::map::Entry;
583 ///
584 /// let mut map = serde_json::Map::new();
585 /// map.insert("serde".to_owned(), json!(12));
586 ///
587 /// match map.entry("serde") {
588 /// Entry::Occupied(occupied) => {
589 /// assert_eq!(occupied.get(), 12);
590 /// }
591 /// Entry::Vacant(_) => unimplemented!(),
592 /// }
593 /// ```
594 #[inline]
595 pub fn get(&self) -> &Value {
596 self.occupied.get()
597 }
598
599 /// Gets a mutable reference to the value in the entry.
600 ///
601 /// # Examples
602 ///
603 /// ```edition2018
604 /// # use serde_json::json;
605 /// #
606 /// use serde_json::map::Entry;
607 ///
608 /// let mut map = serde_json::Map::new();
609 /// map.insert("serde".to_owned(), json!([1, 2, 3]));
610 ///
611 /// match map.entry("serde") {
612 /// Entry::Occupied(mut occupied) => {
613 /// occupied.get_mut().as_array_mut().unwrap().push(json!(4));
614 /// }
615 /// Entry::Vacant(_) => unimplemented!(),
616 /// }
617 ///
618 /// assert_eq!(map["serde"].as_array().unwrap().len(), 4);
619 /// ```
620 #[inline]
621 pub fn get_mut(&mut self) -> &mut Value {
622 self.occupied.get_mut()
623 }
624
625 /// Converts the entry into a mutable reference to its value.
626 ///
627 /// # Examples
628 ///
629 /// ```edition2018
630 /// # use serde_json::json;
631 /// #
632 /// use serde_json::map::Entry;
633 ///
634 /// let mut map = serde_json::Map::new();
635 /// map.insert("serde".to_owned(), json!([1, 2, 3]));
636 ///
637 /// match map.entry("serde") {
638 /// Entry::Occupied(mut occupied) => {
639 /// occupied.into_mut().as_array_mut().unwrap().push(json!(4));
640 /// }
641 /// Entry::Vacant(_) => unimplemented!(),
642 /// }
643 ///
644 /// assert_eq!(map["serde"].as_array().unwrap().len(), 4);
645 /// ```
646 #[inline]
647 pub fn into_mut(self) -> &'a mut Value {
648 self.occupied.into_mut()
649 }
650
651 /// Sets the value of the entry with the `OccupiedEntry`'s key, and returns
652 /// the entry's old value.
653 ///
654 /// # Examples
655 ///
656 /// ```edition2018
657 /// # use serde_json::json;
658 /// #
659 /// use serde_json::map::Entry;
660 ///
661 /// let mut map = serde_json::Map::new();
662 /// map.insert("serde".to_owned(), json!(12));
663 ///
664 /// match map.entry("serde") {
665 /// Entry::Occupied(mut occupied) => {
666 /// assert_eq!(occupied.insert(json!(13)), 12);
667 /// assert_eq!(occupied.get(), 13);
668 /// }
669 /// Entry::Vacant(_) => unimplemented!(),
670 /// }
671 /// ```
672 #[inline]
673 pub fn insert(&mut self, value: Value) -> Value {
674 self.occupied.insert(value)
675 }
676
677 /// Takes the value of the entry out of the map, and returns it.
678 ///
679 /// # Examples
680 ///
681 /// ```edition2018
682 /// # use serde_json::json;
683 /// #
684 /// use serde_json::map::Entry;
685 ///
686 /// let mut map = serde_json::Map::new();
687 /// map.insert("serde".to_owned(), json!(12));
688 ///
689 /// match map.entry("serde") {
690 /// Entry::Occupied(occupied) => {
691 /// assert_eq!(occupied.remove(), 12);
692 /// }
693 /// Entry::Vacant(_) => unimplemented!(),
694 /// }
695 /// ```
696 #[inline]
697 pub fn remove(self) -> Value {
698 #[cfg(feature = "preserve_order")]
699 return self.occupied.swap_remove();
700 #[cfg(not(feature = "preserve_order"))]
701 return self.occupied.remove();
702 }
703}
704
705//////////////////////////////////////////////////////////////////////////////
706
707impl<'a> IntoIterator for &'a Map<String, Value> {
708 type Item = (&'a String, &'a Value);
709 type IntoIter = Iter<'a>;
710 #[inline]
711 fn into_iter(self) -> Self::IntoIter {
712 Iter {
713 iter: self.map.iter(),
714 }
715 }
716}
717
718/// An iterator over a serde_json::Map's entries.
719pub struct Iter<'a> {
720 iter: IterImpl<'a>,
721}
722
723#[cfg(not(feature = "preserve_order"))]
724type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
725#[cfg(feature = "preserve_order")]
726type IterImpl<'a> = indexmap::map::Iter<'a, String, Value>;
727
728delegate_iterator!((Iter<'a>) => (&'a String, &'a Value));
729
730//////////////////////////////////////////////////////////////////////////////
731
732impl<'a> IntoIterator for &'a mut Map<String, Value> {
733 type Item = (&'a String, &'a mut Value);
734 type IntoIter = IterMut<'a>;
735 #[inline]
736 fn into_iter(self) -> Self::IntoIter {
737 IterMut {
738 iter: self.map.iter_mut(),
739 }
740 }
741}
742
743/// A mutable iterator over a serde_json::Map's entries.
744pub struct IterMut<'a> {
745 iter: IterMutImpl<'a>,
746}
747
748#[cfg(not(feature = "preserve_order"))]
749type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
750#[cfg(feature = "preserve_order")]
751type IterMutImpl<'a> = indexmap::map::IterMut<'a, String, Value>;
752
753delegate_iterator!((IterMut<'a>) => (&'a String, &'a mut Value));
754
755//////////////////////////////////////////////////////////////////////////////
756
757impl IntoIterator for Map<String, Value> {
758 type Item = (String, Value);
759 type IntoIter = IntoIter;
760 #[inline]
761 fn into_iter(self) -> Self::IntoIter {
762 IntoIter {
763 iter: self.map.into_iter(),
764 }
765 }
766}
767
768/// An owning iterator over a serde_json::Map's entries.
769pub struct IntoIter {
770 iter: IntoIterImpl,
771}
772
773#[cfg(not(feature = "preserve_order"))]
774type IntoIterImpl = btree_map::IntoIter<String, Value>;
775#[cfg(feature = "preserve_order")]
776type IntoIterImpl = indexmap::map::IntoIter<String, Value>;
777
778delegate_iterator!((IntoIter) => (String, Value));
779
780//////////////////////////////////////////////////////////////////////////////
781
782/// An iterator over a serde_json::Map's keys.
783pub struct Keys<'a> {
784 iter: KeysImpl<'a>,
785}
786
787#[cfg(not(feature = "preserve_order"))]
788type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
789#[cfg(feature = "preserve_order")]
790type KeysImpl<'a> = indexmap::map::Keys<'a, String, Value>;
791
792delegate_iterator!((Keys<'a>) => &'a String);
793
794//////////////////////////////////////////////////////////////////////////////
795
796/// An iterator over a serde_json::Map's values.
797pub struct Values<'a> {
798 iter: ValuesImpl<'a>,
799}
800
801#[cfg(not(feature = "preserve_order"))]
802type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
803#[cfg(feature = "preserve_order")]
804type ValuesImpl<'a> = indexmap::map::Values<'a, String, Value>;
805
806delegate_iterator!((Values<'a>) => &'a Value);
807
808//////////////////////////////////////////////////////////////////////////////
809
810/// A mutable iterator over a serde_json::Map's values.
811pub struct ValuesMut<'a> {
812 iter: ValuesMutImpl<'a>,
813}
814
815#[cfg(not(feature = "preserve_order"))]
816type ValuesMutImpl<'a> = btree_map::ValuesMut<'a, String, Value>;
817#[cfg(feature = "preserve_order")]
818type ValuesMutImpl<'a> = indexmap::map::ValuesMut<'a, String, Value>;
819
820delegate_iterator!((ValuesMut<'a>) => &'a mut Value);