Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Map::into_values method #1226

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading