diff --git a/src/map.rs b/src/map.rs index 3e8a3814c..7ce53069c 100644 --- a/src/map.rs +++ b/src/map.rs @@ -434,13 +434,26 @@ impl<'de> de::Deserialize<'de> for Map { } } -impl FromIterator<(String, Value)> for Map { +impl, V: Into> FromIterator<(K, V)> for Map { + /// Convert an iteratable type to a `Map` + /// + /// # Examples + /// + /// ``` + /// use serde_json::Map; + /// + /// let v: Vec<_> = vec![("lorem", 40), ("ipsum", 2)]; + /// let x: Map<_, _> = v.into_iter().collect(); + /// ``` fn from_iter(iter: T) -> Self where - T: IntoIterator, + T: IntoIterator, { Map { - map: FromIterator::from_iter(iter), + map: iter + .into_iter() + .map(|(k, v)| (k.into(), v.into())) + .collect(), } } }