From d48c224d12a18189bdabbfe050bfe8134dbb4bf5 Mon Sep 17 00:00:00 2001 From: tison Date: Tue, 7 Jan 2025 08:10:53 +0800 Subject: [PATCH] Add Map::into_values method Signed-off-by: tison --- src/map.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/map.rs b/src/map.rs index bc9a9307b..126e8001a 100644 --- a/src/map.rs +++ b/src/map.rs @@ -338,6 +338,14 @@ impl Map { } } + /// Gets an iterator over the values of the map. + #[inline] + pub fn into_values(self) -> IntoValues { + IntoValues { + iter: self.map.into_values(), + } + } + /// Retains only the elements specified by the predicate. /// /// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` @@ -1155,3 +1163,17 @@ type ValuesMutImpl<'a> = btree_map::ValuesMut<'a, String, Value>; type ValuesMutImpl<'a> = indexmap::map::ValuesMut<'a, String, Value>; delegate_iterator!((ValuesMut<'a>) => &'a mut Value); + +////////////////////////////////////////////////////////////////////////////// + +/// An owning iterator over a serde_json::Map's values. +pub struct IntoValues { + iter: IntoValuesImpl, +} + +#[cfg(not(feature = "preserve_order"))] +type IntoValuesImpl = btree_map::IntoValues; +#[cfg(feature = "preserve_order")] +type IntoValuesImpl = indexmap::map::IntoValues; + +delegate_iterator!((IntoValues) => Value);