Skip to content

Commit

Permalink
Add Map::into_values method
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jan 7, 2025
1 parent 1e77cac commit d48c224
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ impl Map<String, Value> {
}
}

/// 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)`
Expand Down Expand Up @@ -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<String, Value>;
#[cfg(feature = "preserve_order")]
type IntoValuesImpl = indexmap::map::IntoValues<String, Value>;

delegate_iterator!((IntoValues) => Value);

0 comments on commit d48c224

Please sign in to comment.