Skip to content

Implement IntoValues and inner converter for Map #1225

Closed
@tisonkun

Description

@tisonkun

Hi @dtolnay!

I'm using the map.rs file in my personal project today, and I made some changes that may be useful for the upstream:

impl<K, V> From<MapImpl<K, V>> for Map<K, V> {
    fn from(map: MapImpl<K, V>) -> Self {
        Map { map }
    }
}

impl Map<String, Value> {
    /// Consumes the `Map`, returning the underlying Map implementation.
    pub fn into_inner(self) -> MapImpl {
        self.map
    }

    /// Gets an iterator over the values of the map.
    #[inline]
    pub fn into_values(self) -> IntoValues {
        IntoValues {
            iter: self.map.into_values(),
        }
    }
}

/// 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);

I'm willing to send a PR if this is desired to be included in the upstream.

Besides, the clippy workaround for derivable_impls seems resolved now. I remove it and no more new warnings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions