Coverage Report

Created: 2025-02-25 06:39

/rust/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.138/src/map.rs
Line
Count
Source (jump to first uncovered line)
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
9
use crate::error::Error;
10
use crate::value::Value;
11
use alloc::string::String;
12
#[cfg(feature = "preserve_order")]
13
use alloc::vec::Vec;
14
use core::borrow::Borrow;
15
use core::fmt::{self, Debug};
16
use core::hash::{Hash, Hasher};
17
use core::iter::FusedIterator;
18
#[cfg(feature = "preserve_order")]
19
use core::mem;
20
use core::ops;
21
use serde::de;
22
23
#[cfg(not(feature = "preserve_order"))]
24
use alloc::collections::{btree_map, BTreeMap};
25
#[cfg(feature = "preserve_order")]
26
use indexmap::IndexMap;
27
28
/// Represents a JSON key/value type.
29
pub struct Map<K, V> {
30
    map: MapImpl<K, V>,
31
}
32
33
#[cfg(not(feature = "preserve_order"))]
34
type MapImpl<K, V> = BTreeMap<K, V>;
35
#[cfg(feature = "preserve_order")]
36
type MapImpl<K, V> = IndexMap<K, V>;
37
38
impl Map<String, Value> {
39
    /// Makes a new empty Map.
40
    #[inline]
41
0
    pub fn new() -> Self {
42
0
        Map {
43
0
            map: MapImpl::new(),
44
0
        }
45
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::new
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::new
46
47
    /// Makes a new empty Map with the given initial capacity.
48
    #[inline]
49
0
    pub fn with_capacity(capacity: usize) -> Self {
50
0
        Map {
51
0
            #[cfg(not(feature = "preserve_order"))]
52
0
            map: {
53
0
                // does not support with_capacity
54
0
                let _ = capacity;
55
0
                BTreeMap::new()
56
0
            },
57
0
            #[cfg(feature = "preserve_order")]
58
0
            map: IndexMap::with_capacity(capacity),
59
0
        }
60
0
    }
61
62
    /// Clears the map, removing all values.
63
    #[inline]
64
0
    pub fn clear(&mut self) {
65
0
        self.map.clear();
66
0
    }
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
0
    pub fn get<Q>(&self, key: &Q) -> Option<&Value>
74
0
    where
75
0
        String: Borrow<Q>,
76
0
        Q: ?Sized + Ord + Eq + Hash,
77
0
    {
78
0
        self.map.get(key)
79
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::get::<alloc::string::String>
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::get::<str>
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
0
    pub fn contains_key<Q>(&self, key: &Q) -> bool
87
0
    where
88
0
        String: Borrow<Q>,
89
0
        Q: ?Sized + Ord + Eq + Hash,
90
0
    {
91
0
        self.map.contains_key(key)
92
0
    }
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
0
    pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut Value>
100
0
    where
101
0
        String: Borrow<Q>,
102
0
        Q: ?Sized + Ord + Eq + Hash,
103
0
    {
104
0
        self.map.get_mut(key)
105
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::get_mut::<alloc::string::String>
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::get_mut::<str>
106
107
    /// Returns the key-value pair matching the given key.
108
    ///
109
    /// The key may be any borrowed form of the map's key type, but the ordering
110
    /// on the borrowed form *must* match the ordering on the key type.
111
    #[inline]
112
0
    pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
113
0
    where
114
0
        String: Borrow<Q>,
115
0
        Q: ?Sized + Ord + Eq + Hash,
116
0
    {
117
0
        self.map.get_key_value(key)
118
0
    }
119
120
    /// Inserts a key-value pair into the map.
121
    ///
122
    /// If the map did not have this key present, `None` is returned.
123
    ///
124
    /// If the map did have this key present, the value is updated, and the old
125
    /// value is returned.
126
    #[inline]
127
0
    pub fn insert(&mut self, k: String, v: Value) -> Option<Value> {
128
0
        self.map.insert(k, v)
129
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::insert
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::insert
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::insert
130
131
    /// Insert a key-value pair in the map at the given index.
132
    ///
133
    /// If the map did not have this key present, `None` is returned.
134
    ///
135
    /// If the map did have this key present, the key is moved to the new
136
    /// position, the value is updated, and the old value is returned.
137
    #[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
    /// Removes a key from the map, returning the value at the key if the key
145
    /// was previously in the map.
146
    ///
147
    /// The key may be any borrowed form of the map's key type, but the ordering
148
    /// on the borrowed form *must* match the ordering on the key type.
149
    ///
150
    /// If serde_json's "preserve_order" is enabled, `.remove(key)` is
151
    /// equivalent to [`.swap_remove(key)`][Self::swap_remove], replacing this
152
    /// entry's position with the last element. If you need to preserve the
153
    /// relative order of the keys in the map, use
154
    /// [`.shift_remove(key)`][Self::shift_remove] instead.
155
    #[inline]
156
0
    pub fn remove<Q>(&mut self, key: &Q) -> Option<Value>
157
0
    where
158
0
        String: Borrow<Q>,
159
0
        Q: ?Sized + Ord + Eq + Hash,
160
0
    {
161
0
        #[cfg(feature = "preserve_order")]
162
0
        return self.swap_remove(key);
163
0
        #[cfg(not(feature = "preserve_order"))]
164
0
        return self.map.remove(key);
165
0
    }
166
167
    /// Removes a key from the map, returning the stored key and value if the
168
    /// key was previously in the map.
169
    ///
170
    /// The key may be any borrowed form of the map's key type, but the ordering
171
    /// on the borrowed form *must* match the ordering on the key type.
172
    ///
173
    /// If serde_json's "preserve_order" is enabled, `.remove_entry(key)` is
174
    /// equivalent to [`.swap_remove_entry(key)`][Self::swap_remove_entry],
175
    /// replacing this entry's position with the last element. If you need to
176
    /// preserve the relative order of the keys in the map, use
177
    /// [`.shift_remove_entry(key)`][Self::shift_remove_entry] instead.
178
    #[inline]
179
0
    pub fn remove_entry<Q>(&mut self, key: &Q) -> Option<(String, Value)>
180
0
    where
181
0
        String: Borrow<Q>,
182
0
        Q: ?Sized + Ord + Eq + Hash,
183
0
    {
184
0
        #[cfg(feature = "preserve_order")]
185
0
        return self.swap_remove_entry(key);
186
0
        #[cfg(not(feature = "preserve_order"))]
187
0
        return self.map.remove_entry(key);
188
0
    }
189
190
    /// Removes and returns the value corresponding to the key from the map.
191
    ///
192
    /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
193
    /// last element of the map and popping it off. This perturbs the position
194
    /// of what used to be the last element!
195
    ///
196
    /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
197
    #[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
    /// Remove and return the key-value pair.
209
    ///
210
    /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
211
    /// last element of the map and popping it off. This perturbs the position
212
    /// of what used to be the last element!
213
    ///
214
    /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
215
    #[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
    /// Removes and returns the value corresponding to the key from the map.
227
    ///
228
    /// Like [`Vec::remove`], the entry is removed by shifting all of the
229
    /// elements that follow it, preserving their relative order. This perturbs
230
    /// the index of all of those elements!
231
    ///
232
    /// [`Vec::remove`]: std::vec::Vec::remove
233
    #[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
    /// Remove and return the key-value pair.
245
    ///
246
    /// Like [`Vec::remove`], the entry is removed by shifting all of the
247
    /// elements that follow it, preserving their relative order. This perturbs
248
    /// the index of all of those elements!
249
    ///
250
    /// [`Vec::remove`]: std::vec::Vec::remove
251
    #[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
    /// Moves all elements from other into self, leaving other empty.
263
    #[inline]
264
0
    pub fn append(&mut self, other: &mut Self) {
265
0
        #[cfg(feature = "preserve_order")]
266
0
        self.map
267
0
            .extend(mem::replace(&mut other.map, MapImpl::default()));
268
0
        #[cfg(not(feature = "preserve_order"))]
269
0
        self.map.append(&mut other.map);
270
0
    }
271
272
    /// Gets the given key's corresponding entry in the map for in-place
273
    /// manipulation.
274
0
    pub fn entry<S>(&mut self, key: S) -> Entry
275
0
    where
276
0
        S: Into<String>,
277
0
    {
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
0
        match self.map.entry(key.into()) {
284
0
            EntryImpl::Vacant(vacant) => Entry::Vacant(VacantEntry { vacant }),
285
0
            EntryImpl::Occupied(occupied) => Entry::Occupied(OccupiedEntry { occupied }),
286
        }
287
0
    }
288
289
    /// Returns the number of elements in the map.
290
    #[inline]
291
0
    pub fn len(&self) -> usize {
292
0
        self.map.len()
293
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::len
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::len
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::len
294
295
    /// Returns true if the map contains no elements.
296
    #[inline]
297
0
    pub fn is_empty(&self) -> bool {
298
0
        self.map.is_empty()
299
0
    }
300
301
    /// Gets an iterator over the entries of the map.
302
    #[inline]
303
0
    pub fn iter(&self) -> Iter {
304
0
        Iter {
305
0
            iter: self.map.iter(),
306
0
        }
307
0
    }
308
309
    /// Gets a mutable iterator over the entries of the map.
310
    #[inline]
311
0
    pub fn iter_mut(&mut self) -> IterMut {
312
0
        IterMut {
313
0
            iter: self.map.iter_mut(),
314
0
        }
315
0
    }
316
317
    /// Gets an iterator over the keys of the map.
318
    #[inline]
319
0
    pub fn keys(&self) -> Keys {
320
0
        Keys {
321
0
            iter: self.map.keys(),
322
0
        }
323
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::keys
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value>>::keys
324
325
    /// Gets an iterator over the values of the map.
326
    #[inline]
327
0
    pub fn values(&self) -> Values {
328
0
        Values {
329
0
            iter: self.map.values(),
330
0
        }
331
0
    }
332
333
    /// Gets an iterator over mutable values of the map.
334
    #[inline]
335
0
    pub fn values_mut(&mut self) -> ValuesMut {
336
0
        ValuesMut {
337
0
            iter: self.map.values_mut(),
338
0
        }
339
0
    }
340
341
    /// Gets an iterator over the values of the map.
342
    #[inline]
343
0
    pub fn into_values(self) -> IntoValues {
344
0
        IntoValues {
345
0
            iter: self.map.into_values(),
346
0
        }
347
0
    }
348
349
    /// Retains only the elements specified by the predicate.
350
    ///
351
    /// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
352
    /// returns `false`.
353
    #[inline]
354
0
    pub fn retain<F>(&mut self, f: F)
355
0
    where
356
0
        F: FnMut(&String, &mut Value) -> bool,
357
0
    {
358
0
        self.map.retain(f);
359
0
    }
360
361
    /// Sorts this map's entries in-place using `str`'s usual ordering.
362
    ///
363
    /// If serde_json's "preserve_order" feature is not enabled, this method
364
    /// does no work because all JSON maps are always kept in a sorted state.
365
    ///
366
    /// If serde_json's "preserve_order" feature is enabled, this method
367
    /// destroys the original source order or insertion order of this map in
368
    /// favor of an alphanumerical order that matches how a BTreeMap with the
369
    /// same contents would be ordered. This takes **O(n log n + c)** time where
370
    /// _n_ is the length of the map and _c_ is the capacity.
371
    ///
372
    /// Other maps nested within the values of this map are not sorted. If you
373
    /// need the entire data structure to be sorted at all levels, you must also
374
    /// call
375
    /// <code>map.[values_mut]\().for_each([Value::sort_all_objects])</code>.
376
    ///
377
    /// [values_mut]: Map::values_mut
378
    #[inline]
379
0
    pub fn sort_keys(&mut self) {
380
0
        #[cfg(feature = "preserve_order")]
381
0
        self.map.sort_unstable_keys();
382
0
    }
383
}
384
385
#[allow(clippy::derivable_impls)] // clippy bug: https://github.com/rust-lang/rust-clippy/issues/7655
386
impl Default for Map<String, Value> {
387
    #[inline]
388
0
    fn default() -> Self {
389
0
        Map {
390
0
            map: MapImpl::new(),
391
0
        }
392
0
    }
393
}
394
395
impl Clone for Map<String, Value> {
396
    #[inline]
397
0
    fn clone(&self) -> Self {
398
0
        Map {
399
0
            map: self.map.clone(),
400
0
        }
401
0
    }
402
403
    #[inline]
404
0
    fn clone_from(&mut self, source: &Self) {
405
0
        self.map.clone_from(&source.map);
406
0
    }
407
}
408
409
impl PartialEq for Map<String, Value> {
410
    #[inline]
411
0
    fn eq(&self, other: &Self) -> bool {
412
0
        self.map.eq(&other.map)
413
0
    }
414
}
415
416
impl Eq for Map<String, Value> {}
417
418
impl Hash for Map<String, Value> {
419
0
    fn hash<H: Hasher>(&self, state: &mut H) {
420
0
        #[cfg(not(feature = "preserve_order"))]
421
0
        {
422
0
            self.map.hash(state);
423
0
        }
424
0
425
0
        #[cfg(feature = "preserve_order")]
426
0
        {
427
0
            let mut kv = Vec::from_iter(&self.map);
428
0
            kv.sort_unstable_by(|a, b| a.0.cmp(b.0));
429
0
            kv.hash(state);
430
0
        }
431
0
    }
432
}
433
434
/// Access an element of this map. Panics if the given key is not present in the
435
/// map.
436
///
437
/// ```
438
/// # use serde_json::Value;
439
/// #
440
/// # let val = &Value::String("".to_owned());
441
/// # let _ =
442
/// match val {
443
///     Value::String(s) => Some(s.as_str()),
444
///     Value::Array(arr) => arr[0].as_str(),
445
///     Value::Object(map) => map["type"].as_str(),
446
///     _ => None,
447
/// }
448
/// # ;
449
/// ```
450
impl<Q> ops::Index<&Q> for Map<String, Value>
451
where
452
    String: Borrow<Q>,
453
    Q: ?Sized + Ord + Eq + Hash,
454
{
455
    type Output = Value;
456
457
0
    fn index(&self, index: &Q) -> &Value {
458
0
        self.map.index(index)
459
0
    }
460
}
461
462
/// Mutably access an element of this map. Panics if the given key is not
463
/// present in the map.
464
///
465
/// ```
466
/// # use serde_json::json;
467
/// #
468
/// # let mut map = serde_json::Map::new();
469
/// # map.insert("key".to_owned(), serde_json::Value::Null);
470
/// #
471
/// map["key"] = json!("value");
472
/// ```
473
impl<Q> ops::IndexMut<&Q> for Map<String, Value>
474
where
475
    String: Borrow<Q>,
476
    Q: ?Sized + Ord + Eq + Hash,
477
{
478
0
    fn index_mut(&mut self, index: &Q) -> &mut Value {
479
0
        self.map.get_mut(index).expect("no entry found for key")
480
0
    }
481
}
482
483
impl Debug for Map<String, Value> {
484
    #[inline]
485
0
    fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
486
0
        self.map.fmt(formatter)
487
0
    }
488
}
489
490
#[cfg(any(feature = "std", feature = "alloc"))]
491
impl serde::ser::Serialize for Map<String, Value> {
492
    #[inline]
493
0
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
494
0
    where
495
0
        S: serde::ser::Serializer,
496
0
    {
497
        use serde::ser::SerializeMap;
498
0
        let mut map = tri!(serializer.serialize_map(Some(self.len())));
499
0
        for (k, v) in self {
500
0
            tri!(map.serialize_entry(k, v));
501
        }
502
0
        map.end()
503
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value> as serde::ser::Serialize>::serialize::<&mut serde_json::ser::Serializer<&mut alloc::vec::Vec<u8>, serde_json::ser::PrettyFormatter>>
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value> as serde::ser::Serialize>::serialize::<_>
504
}
505
506
impl<'de> de::Deserialize<'de> for Map<String, Value> {
507
    #[inline]
508
0
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
509
0
    where
510
0
        D: de::Deserializer<'de>,
511
0
    {
512
        struct Visitor;
513
514
        impl<'de> de::Visitor<'de> for Visitor {
515
            type Value = Map<String, Value>;
516
517
0
            fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
518
0
                formatter.write_str("a map")
519
0
            }
520
521
            #[inline]
522
0
            fn visit_unit<E>(self) -> Result<Self::Value, E>
523
0
            where
524
0
                E: de::Error,
525
0
            {
526
0
                Ok(Map::new())
527
0
            }
528
529
            #[cfg(any(feature = "std", feature = "alloc"))]
530
            #[inline]
531
0
            fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
532
0
            where
533
0
                V: de::MapAccess<'de>,
534
0
            {
535
0
                let mut values = Map::new();
536
537
0
                while let Some((key, value)) = tri!(visitor.next_entry()) {
538
0
                    values.insert(key, value);
539
0
                }
540
541
0
                Ok(values)
542
0
            }
543
        }
544
545
0
        deserializer.deserialize_map(Visitor)
546
0
    }
547
}
548
549
impl FromIterator<(String, Value)> for Map<String, Value> {
550
0
    fn from_iter<T>(iter: T) -> Self
551
0
    where
552
0
        T: IntoIterator<Item = (String, Value)>,
553
0
    {
554
0
        Map {
555
0
            map: FromIterator::from_iter(iter),
556
0
        }
557
0
    }
558
}
559
560
impl Extend<(String, Value)> for Map<String, Value> {
561
0
    fn extend<T>(&mut self, iter: T)
562
0
    where
563
0
        T: IntoIterator<Item = (String, Value)>,
564
0
    {
565
0
        self.map.extend(iter);
566
0
    }
567
}
568
569
macro_rules! delegate_iterator {
570
    (($name:ident $($generics:tt)*) => $item:ty) => {
571
        impl $($generics)* Iterator for $name $($generics)* {
572
            type Item = $item;
573
            #[inline]
574
0
            fn next(&mut self) -> Option<Self::Item> {
575
0
                self.iter.next()
576
0
            }
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::Keys as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::IterMut as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::Keys as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::Values as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::ValuesMut as core::iter::traits::iterator::Iterator>::next
Unexecuted instantiation: <serde_json::map::IntoValues as core::iter::traits::iterator::Iterator>::next
577
            #[inline]
578
0
            fn size_hint(&self) -> (usize, Option<usize>) {
579
0
                self.iter.size_hint()
580
0
            }
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::IterMut as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::Keys as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::Values as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::ValuesMut as core::iter::traits::iterator::Iterator>::size_hint
Unexecuted instantiation: <serde_json::map::IntoValues as core::iter::traits::iterator::Iterator>::size_hint
581
        }
582
583
        impl $($generics)* DoubleEndedIterator for $name $($generics)* {
584
            #[inline]
585
0
            fn next_back(&mut self) -> Option<Self::Item> {
586
0
                self.iter.next_back()
587
0
            }
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::IterMut as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::Keys as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::Values as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::ValuesMut as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
Unexecuted instantiation: <serde_json::map::IntoValues as core::iter::traits::double_ended::DoubleEndedIterator>::next_back
588
        }
589
590
        impl $($generics)* ExactSizeIterator for $name $($generics)* {
591
            #[inline]
592
0
            fn len(&self) -> usize {
593
0
                self.iter.len()
594
0
            }
Unexecuted instantiation: <serde_json::map::Iter as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::IterMut as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::IntoIter as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::Keys as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::Values as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::ValuesMut as core::iter::traits::exact_size::ExactSizeIterator>::len
Unexecuted instantiation: <serde_json::map::IntoValues as core::iter::traits::exact_size::ExactSizeIterator>::len
595
        }
596
597
        impl $($generics)* FusedIterator for $name $($generics)* {}
598
    }
599
}
600
601
impl<'de> de::IntoDeserializer<'de, Error> for Map<String, Value> {
602
    type Deserializer = Self;
603
604
0
    fn into_deserializer(self) -> Self::Deserializer {
605
0
        self
606
0
    }
607
}
608
609
impl<'de> de::IntoDeserializer<'de, Error> for &'de Map<String, Value> {
610
    type Deserializer = Self;
611
612
0
    fn into_deserializer(self) -> Self::Deserializer {
613
0
        self
614
0
    }
615
}
616
617
//////////////////////////////////////////////////////////////////////////////
618
619
/// A view into a single entry in a map, which may either be vacant or occupied.
620
/// This enum is constructed from the [`entry`] method on [`Map`].
621
///
622
/// [`entry`]: struct.Map.html#method.entry
623
/// [`Map`]: struct.Map.html
624
pub enum Entry<'a> {
625
    /// A vacant Entry.
626
    Vacant(VacantEntry<'a>),
627
    /// An occupied Entry.
628
    Occupied(OccupiedEntry<'a>),
629
}
630
631
/// A vacant Entry. It is part of the [`Entry`] enum.
632
///
633
/// [`Entry`]: enum.Entry.html
634
pub struct VacantEntry<'a> {
635
    vacant: VacantEntryImpl<'a>,
636
}
637
638
/// An occupied Entry. It is part of the [`Entry`] enum.
639
///
640
/// [`Entry`]: enum.Entry.html
641
pub struct OccupiedEntry<'a> {
642
    occupied: OccupiedEntryImpl<'a>,
643
}
644
645
#[cfg(not(feature = "preserve_order"))]
646
type VacantEntryImpl<'a> = btree_map::VacantEntry<'a, String, Value>;
647
#[cfg(feature = "preserve_order")]
648
type VacantEntryImpl<'a> = indexmap::map::VacantEntry<'a, String, Value>;
649
650
#[cfg(not(feature = "preserve_order"))]
651
type OccupiedEntryImpl<'a> = btree_map::OccupiedEntry<'a, String, Value>;
652
#[cfg(feature = "preserve_order")]
653
type OccupiedEntryImpl<'a> = indexmap::map::OccupiedEntry<'a, String, Value>;
654
655
impl<'a> Entry<'a> {
656
    /// Returns a reference to this entry's key.
657
    ///
658
    /// # Examples
659
    ///
660
    /// ```
661
    /// let mut map = serde_json::Map::new();
662
    /// assert_eq!(map.entry("serde").key(), &"serde");
663
    /// ```
664
0
    pub fn key(&self) -> &String {
665
0
        match self {
666
0
            Entry::Vacant(e) => e.key(),
667
0
            Entry::Occupied(e) => e.key(),
668
        }
669
0
    }
670
671
    /// Ensures a value is in the entry by inserting the default if empty, and
672
    /// returns a mutable reference to the value in the entry.
673
    ///
674
    /// # Examples
675
    ///
676
    /// ```
677
    /// # use serde_json::json;
678
    /// #
679
    /// let mut map = serde_json::Map::new();
680
    /// map.entry("serde").or_insert(json!(12));
681
    ///
682
    /// assert_eq!(map["serde"], 12);
683
    /// ```
684
0
    pub fn or_insert(self, default: Value) -> &'a mut Value {
685
0
        match self {
686
0
            Entry::Vacant(entry) => entry.insert(default),
687
0
            Entry::Occupied(entry) => entry.into_mut(),
688
        }
689
0
    }
690
691
    /// Ensures a value is in the entry by inserting the result of the default
692
    /// function if empty, and returns a mutable reference to the value in the
693
    /// entry.
694
    ///
695
    /// # Examples
696
    ///
697
    /// ```
698
    /// # use serde_json::json;
699
    /// #
700
    /// let mut map = serde_json::Map::new();
701
    /// map.entry("serde").or_insert_with(|| json!("hoho"));
702
    ///
703
    /// assert_eq!(map["serde"], "hoho".to_owned());
704
    /// ```
705
0
    pub fn or_insert_with<F>(self, default: F) -> &'a mut Value
706
0
    where
707
0
        F: FnOnce() -> Value,
708
0
    {
709
0
        match self {
710
0
            Entry::Vacant(entry) => entry.insert(default()),
711
0
            Entry::Occupied(entry) => entry.into_mut(),
712
        }
713
0
    }
714
715
    /// Provides in-place mutable access to an occupied entry before any
716
    /// potential inserts into the map.
717
    ///
718
    /// # Examples
719
    ///
720
    /// ```
721
    /// # use serde_json::json;
722
    /// #
723
    /// let mut map = serde_json::Map::new();
724
    /// map.entry("serde")
725
    ///     .and_modify(|e| *e = json!("rust"))
726
    ///     .or_insert(json!("cpp"));
727
    ///
728
    /// assert_eq!(map["serde"], "cpp");
729
    ///
730
    /// map.entry("serde")
731
    ///     .and_modify(|e| *e = json!("rust"))
732
    ///     .or_insert(json!("cpp"));
733
    ///
734
    /// assert_eq!(map["serde"], "rust");
735
    /// ```
736
0
    pub fn and_modify<F>(self, f: F) -> Self
737
0
    where
738
0
        F: FnOnce(&mut Value),
739
0
    {
740
0
        match self {
741
0
            Entry::Occupied(mut entry) => {
742
0
                f(entry.get_mut());
743
0
                Entry::Occupied(entry)
744
            }
745
0
            Entry::Vacant(entry) => Entry::Vacant(entry),
746
        }
747
0
    }
748
}
749
750
impl<'a> VacantEntry<'a> {
751
    /// Gets a reference to the key that would be used when inserting a value
752
    /// through the VacantEntry.
753
    ///
754
    /// # Examples
755
    ///
756
    /// ```
757
    /// use serde_json::map::Entry;
758
    ///
759
    /// let mut map = serde_json::Map::new();
760
    ///
761
    /// match map.entry("serde") {
762
    ///     Entry::Vacant(vacant) => {
763
    ///         assert_eq!(vacant.key(), &"serde");
764
    ///     }
765
    ///     Entry::Occupied(_) => unimplemented!(),
766
    /// }
767
    /// ```
768
    #[inline]
769
0
    pub fn key(&self) -> &String {
770
0
        self.vacant.key()
771
0
    }
772
773
    /// Sets the value of the entry with the VacantEntry's key, and returns a
774
    /// mutable reference to it.
775
    ///
776
    /// # Examples
777
    ///
778
    /// ```
779
    /// # use serde_json::json;
780
    /// #
781
    /// use serde_json::map::Entry;
782
    ///
783
    /// let mut map = serde_json::Map::new();
784
    ///
785
    /// match map.entry("serde") {
786
    ///     Entry::Vacant(vacant) => {
787
    ///         vacant.insert(json!("hoho"));
788
    ///     }
789
    ///     Entry::Occupied(_) => unimplemented!(),
790
    /// }
791
    /// ```
792
    #[inline]
793
0
    pub fn insert(self, value: Value) -> &'a mut Value {
794
0
        self.vacant.insert(value)
795
0
    }
796
}
797
798
impl<'a> OccupiedEntry<'a> {
799
    /// Gets a reference to the key in the entry.
800
    ///
801
    /// # Examples
802
    ///
803
    /// ```
804
    /// # use serde_json::json;
805
    /// #
806
    /// use serde_json::map::Entry;
807
    ///
808
    /// let mut map = serde_json::Map::new();
809
    /// map.insert("serde".to_owned(), json!(12));
810
    ///
811
    /// match map.entry("serde") {
812
    ///     Entry::Occupied(occupied) => {
813
    ///         assert_eq!(occupied.key(), &"serde");
814
    ///     }
815
    ///     Entry::Vacant(_) => unimplemented!(),
816
    /// }
817
    /// ```
818
    #[inline]
819
0
    pub fn key(&self) -> &String {
820
0
        self.occupied.key()
821
0
    }
822
823
    /// Gets a reference to the value in the entry.
824
    ///
825
    /// # Examples
826
    ///
827
    /// ```
828
    /// # use serde_json::json;
829
    /// #
830
    /// use serde_json::map::Entry;
831
    ///
832
    /// let mut map = serde_json::Map::new();
833
    /// map.insert("serde".to_owned(), json!(12));
834
    ///
835
    /// match map.entry("serde") {
836
    ///     Entry::Occupied(occupied) => {
837
    ///         assert_eq!(occupied.get(), 12);
838
    ///     }
839
    ///     Entry::Vacant(_) => unimplemented!(),
840
    /// }
841
    /// ```
842
    #[inline]
843
0
    pub fn get(&self) -> &Value {
844
0
        self.occupied.get()
845
0
    }
846
847
    /// Gets a mutable reference to the value in the entry.
848
    ///
849
    /// # Examples
850
    ///
851
    /// ```
852
    /// # use serde_json::json;
853
    /// #
854
    /// use serde_json::map::Entry;
855
    ///
856
    /// let mut map = serde_json::Map::new();
857
    /// map.insert("serde".to_owned(), json!([1, 2, 3]));
858
    ///
859
    /// match map.entry("serde") {
860
    ///     Entry::Occupied(mut occupied) => {
861
    ///         occupied.get_mut().as_array_mut().unwrap().push(json!(4));
862
    ///     }
863
    ///     Entry::Vacant(_) => unimplemented!(),
864
    /// }
865
    ///
866
    /// assert_eq!(map["serde"].as_array().unwrap().len(), 4);
867
    /// ```
868
    #[inline]
869
0
    pub fn get_mut(&mut self) -> &mut Value {
870
0
        self.occupied.get_mut()
871
0
    }
872
873
    /// Converts the entry into a mutable reference to its value.
874
    ///
875
    /// # Examples
876
    ///
877
    /// ```
878
    /// # use serde_json::json;
879
    /// #
880
    /// use serde_json::map::Entry;
881
    ///
882
    /// let mut map = serde_json::Map::new();
883
    /// map.insert("serde".to_owned(), json!([1, 2, 3]));
884
    ///
885
    /// match map.entry("serde") {
886
    ///     Entry::Occupied(mut occupied) => {
887
    ///         occupied.into_mut().as_array_mut().unwrap().push(json!(4));
888
    ///     }
889
    ///     Entry::Vacant(_) => unimplemented!(),
890
    /// }
891
    ///
892
    /// assert_eq!(map["serde"].as_array().unwrap().len(), 4);
893
    /// ```
894
    #[inline]
895
0
    pub fn into_mut(self) -> &'a mut Value {
896
0
        self.occupied.into_mut()
897
0
    }
898
899
    /// Sets the value of the entry with the `OccupiedEntry`'s key, and returns
900
    /// the entry's old value.
901
    ///
902
    /// # Examples
903
    ///
904
    /// ```
905
    /// # use serde_json::json;
906
    /// #
907
    /// use serde_json::map::Entry;
908
    ///
909
    /// let mut map = serde_json::Map::new();
910
    /// map.insert("serde".to_owned(), json!(12));
911
    ///
912
    /// match map.entry("serde") {
913
    ///     Entry::Occupied(mut occupied) => {
914
    ///         assert_eq!(occupied.insert(json!(13)), 12);
915
    ///         assert_eq!(occupied.get(), 13);
916
    ///     }
917
    ///     Entry::Vacant(_) => unimplemented!(),
918
    /// }
919
    /// ```
920
    #[inline]
921
0
    pub fn insert(&mut self, value: Value) -> Value {
922
0
        self.occupied.insert(value)
923
0
    }
924
925
    /// Takes the value of the entry out of the map, and returns it.
926
    ///
927
    /// If serde_json's "preserve_order" is enabled, `.remove()` is
928
    /// equivalent to [`.swap_remove()`][Self::swap_remove], replacing this
929
    /// entry's position with the last element. If you need to preserve the
930
    /// relative order of the keys in the map, use
931
    /// [`.shift_remove()`][Self::shift_remove] instead.
932
    ///
933
    /// # Examples
934
    ///
935
    /// ```
936
    /// # use serde_json::json;
937
    /// #
938
    /// use serde_json::map::Entry;
939
    ///
940
    /// let mut map = serde_json::Map::new();
941
    /// map.insert("serde".to_owned(), json!(12));
942
    ///
943
    /// match map.entry("serde") {
944
    ///     Entry::Occupied(occupied) => {
945
    ///         assert_eq!(occupied.remove(), 12);
946
    ///     }
947
    ///     Entry::Vacant(_) => unimplemented!(),
948
    /// }
949
    /// ```
950
    #[inline]
951
0
    pub fn remove(self) -> Value {
952
0
        #[cfg(feature = "preserve_order")]
953
0
        return self.swap_remove();
954
0
        #[cfg(not(feature = "preserve_order"))]
955
0
        return self.occupied.remove();
956
0
    }
957
958
    /// Takes the value of the entry out of the map, and returns it.
959
    ///
960
    /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
961
    /// last element of the map and popping it off. This perturbs the position
962
    /// of what used to be the last element!
963
    ///
964
    /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
965
    #[cfg(feature = "preserve_order")]
966
    #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
967
    #[inline]
968
    pub fn swap_remove(self) -> Value {
969
        self.occupied.swap_remove()
970
    }
971
972
    /// Takes the value of the entry out of the map, and returns it.
973
    ///
974
    /// Like [`Vec::remove`], the entry is removed by shifting all of the
975
    /// elements that follow it, preserving their relative order. This perturbs
976
    /// the index of all of those elements!
977
    ///
978
    /// [`Vec::remove`]: std::vec::Vec::remove
979
    #[cfg(feature = "preserve_order")]
980
    #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
981
    #[inline]
982
    pub fn shift_remove(self) -> Value {
983
        self.occupied.shift_remove()
984
    }
985
986
    /// Removes the entry from the map, returning the stored key and value.
987
    ///
988
    /// If serde_json's "preserve_order" is enabled, `.remove_entry()` is
989
    /// equivalent to [`.swap_remove_entry()`][Self::swap_remove_entry],
990
    /// replacing this entry's position with the last element. If you need to
991
    /// preserve the relative order of the keys in the map, use
992
    /// [`.shift_remove_entry()`][Self::shift_remove_entry] instead.
993
    ///
994
    /// # Examples
995
    ///
996
    /// ```
997
    /// # use serde_json::json;
998
    /// #
999
    /// use serde_json::map::Entry;
1000
    ///
1001
    /// let mut map = serde_json::Map::new();
1002
    /// map.insert("serde".to_owned(), json!(12));
1003
    ///
1004
    /// match map.entry("serde") {
1005
    ///     Entry::Occupied(occupied) => {
1006
    ///         let (key, value) = occupied.remove_entry();
1007
    ///         assert_eq!(key, "serde");
1008
    ///         assert_eq!(value, 12);
1009
    ///     }
1010
    ///     Entry::Vacant(_) => unimplemented!(),
1011
    /// }
1012
    /// ```
1013
    #[inline]
1014
0
    pub fn remove_entry(self) -> (String, Value) {
1015
0
        #[cfg(feature = "preserve_order")]
1016
0
        return self.swap_remove_entry();
1017
0
        #[cfg(not(feature = "preserve_order"))]
1018
0
        return self.occupied.remove_entry();
1019
0
    }
1020
1021
    /// Removes the entry from the map, returning the stored key and value.
1022
    ///
1023
    /// Like [`Vec::swap_remove`], the entry is removed by swapping it with the
1024
    /// last element of the map and popping it off. This perturbs the position
1025
    /// of what used to be the last element!
1026
    ///
1027
    /// [`Vec::swap_remove`]: std::vec::Vec::swap_remove
1028
    #[cfg(feature = "preserve_order")]
1029
    #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
1030
    #[inline]
1031
    pub fn swap_remove_entry(self) -> (String, Value) {
1032
        self.occupied.swap_remove_entry()
1033
    }
1034
1035
    /// Removes the entry from the map, returning the stored key and value.
1036
    ///
1037
    /// Like [`Vec::remove`], the entry is removed by shifting all of the
1038
    /// elements that follow it, preserving their relative order. This perturbs
1039
    /// the index of all of those elements!
1040
    ///
1041
    /// [`Vec::remove`]: std::vec::Vec::remove
1042
    #[cfg(feature = "preserve_order")]
1043
    #[cfg_attr(docsrs, doc(cfg(feature = "preserve_order")))]
1044
    #[inline]
1045
    pub fn shift_remove_entry(self) -> (String, Value) {
1046
        self.occupied.shift_remove_entry()
1047
    }
1048
}
1049
1050
//////////////////////////////////////////////////////////////////////////////
1051
1052
impl<'a> IntoIterator for &'a Map<String, Value> {
1053
    type Item = (&'a String, &'a Value);
1054
    type IntoIter = Iter<'a>;
1055
    #[inline]
1056
0
    fn into_iter(self) -> Self::IntoIter {
1057
0
        Iter {
1058
0
            iter: self.map.iter(),
1059
0
        }
1060
0
    }
Unexecuted instantiation: <&serde_json::map::Map<alloc::string::String, serde_json::value::Value> as core::iter::traits::collect::IntoIterator>::into_iter
Unexecuted instantiation: <&serde_json::map::Map<alloc::string::String, serde_json::value::Value> as core::iter::traits::collect::IntoIterator>::into_iter
Unexecuted instantiation: <&serde_json::map::Map<alloc::string::String, serde_json::value::Value> as core::iter::traits::collect::IntoIterator>::into_iter
1061
}
1062
1063
/// An iterator over a serde_json::Map's entries.
1064
pub struct Iter<'a> {
1065
    iter: IterImpl<'a>,
1066
}
1067
1068
#[cfg(not(feature = "preserve_order"))]
1069
type IterImpl<'a> = btree_map::Iter<'a, String, Value>;
1070
#[cfg(feature = "preserve_order")]
1071
type IterImpl<'a> = indexmap::map::Iter<'a, String, Value>;
1072
1073
delegate_iterator!((Iter<'a>) => (&'a String, &'a Value));
1074
1075
//////////////////////////////////////////////////////////////////////////////
1076
1077
impl<'a> IntoIterator for &'a mut Map<String, Value> {
1078
    type Item = (&'a String, &'a mut Value);
1079
    type IntoIter = IterMut<'a>;
1080
    #[inline]
1081
0
    fn into_iter(self) -> Self::IntoIter {
1082
0
        IterMut {
1083
0
            iter: self.map.iter_mut(),
1084
0
        }
1085
0
    }
1086
}
1087
1088
/// A mutable iterator over a serde_json::Map's entries.
1089
pub struct IterMut<'a> {
1090
    iter: IterMutImpl<'a>,
1091
}
1092
1093
#[cfg(not(feature = "preserve_order"))]
1094
type IterMutImpl<'a> = btree_map::IterMut<'a, String, Value>;
1095
#[cfg(feature = "preserve_order")]
1096
type IterMutImpl<'a> = indexmap::map::IterMut<'a, String, Value>;
1097
1098
delegate_iterator!((IterMut<'a>) => (&'a String, &'a mut Value));
1099
1100
//////////////////////////////////////////////////////////////////////////////
1101
1102
impl IntoIterator for Map<String, Value> {
1103
    type Item = (String, Value);
1104
    type IntoIter = IntoIter;
1105
    #[inline]
1106
0
    fn into_iter(self) -> Self::IntoIter {
1107
0
        IntoIter {
1108
0
            iter: self.map.into_iter(),
1109
0
        }
1110
0
    }
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value> as core::iter::traits::collect::IntoIterator>::into_iter
Unexecuted instantiation: <serde_json::map::Map<alloc::string::String, serde_json::value::Value> as core::iter::traits::collect::IntoIterator>::into_iter
1111
}
1112
1113
/// An owning iterator over a serde_json::Map's entries.
1114
pub struct IntoIter {
1115
    iter: IntoIterImpl,
1116
}
1117
1118
#[cfg(not(feature = "preserve_order"))]
1119
type IntoIterImpl = btree_map::IntoIter<String, Value>;
1120
#[cfg(feature = "preserve_order")]
1121
type IntoIterImpl = indexmap::map::IntoIter<String, Value>;
1122
1123
delegate_iterator!((IntoIter) => (String, Value));
1124
1125
//////////////////////////////////////////////////////////////////////////////
1126
1127
/// An iterator over a serde_json::Map's keys.
1128
pub struct Keys<'a> {
1129
    iter: KeysImpl<'a>,
1130
}
1131
1132
#[cfg(not(feature = "preserve_order"))]
1133
type KeysImpl<'a> = btree_map::Keys<'a, String, Value>;
1134
#[cfg(feature = "preserve_order")]
1135
type KeysImpl<'a> = indexmap::map::Keys<'a, String, Value>;
1136
1137
delegate_iterator!((Keys<'a>) => &'a String);
1138
1139
//////////////////////////////////////////////////////////////////////////////
1140
1141
/// An iterator over a serde_json::Map's values.
1142
pub struct Values<'a> {
1143
    iter: ValuesImpl<'a>,
1144
}
1145
1146
#[cfg(not(feature = "preserve_order"))]
1147
type ValuesImpl<'a> = btree_map::Values<'a, String, Value>;
1148
#[cfg(feature = "preserve_order")]
1149
type ValuesImpl<'a> = indexmap::map::Values<'a, String, Value>;
1150
1151
delegate_iterator!((Values<'a>) => &'a Value);
1152
1153
//////////////////////////////////////////////////////////////////////////////
1154
1155
/// A mutable iterator over a serde_json::Map's values.
1156
pub struct ValuesMut<'a> {
1157
    iter: ValuesMutImpl<'a>,
1158
}
1159
1160
#[cfg(not(feature = "preserve_order"))]
1161
type ValuesMutImpl<'a> = btree_map::ValuesMut<'a, String, Value>;
1162
#[cfg(feature = "preserve_order")]
1163
type ValuesMutImpl<'a> = indexmap::map::ValuesMut<'a, String, Value>;
1164
1165
delegate_iterator!((ValuesMut<'a>) => &'a mut Value);
1166
1167
//////////////////////////////////////////////////////////////////////////////
1168
1169
/// An owning iterator over a serde_json::Map's values.
1170
pub struct IntoValues {
1171
    iter: IntoValuesImpl,
1172
}
1173
1174
#[cfg(not(feature = "preserve_order"))]
1175
type IntoValuesImpl = btree_map::IntoValues<String, Value>;
1176
#[cfg(feature = "preserve_order")]
1177
type IntoValuesImpl = indexmap::map::IntoValues<String, Value>;
1178
1179
delegate_iterator!((IntoValues) => Value);