Skip to content

Commit

Permalink
Merge pull request #240 from Kroisse/from-iterator-for-map
Browse files Browse the repository at this point in the history
Implement FromIterator and Extend for value::Map
  • Loading branch information
dtolnay authored Feb 3, 2017
2 parents 248df27 + 9286682 commit 9984a31
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions json/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{ser, de};
use std::fmt::{self, Debug};
use value::Value;
use std::hash::Hash;
use std::iter::FromIterator;
use std::borrow::Borrow;
use std::ops;

Expand Down Expand Up @@ -274,6 +275,20 @@ impl de::Deserialize for Map<String, Value> {
}
}

impl FromIterator<(String, Value)> for Map<String, Value> {
fn from_iter<T>(iter: T) -> Self where T: IntoIterator<Item=(String, Value)> {
Map {
map: FromIterator::from_iter(iter)
}
}
}

impl Extend<(String, Value)> for Map<String, Value> {
fn extend<T>(&mut self, iter: T) where T: IntoIterator<Item=(String, Value)> {
self.map.extend(iter);
}
}

macro_rules! delegate_iterator {
(($name:ident $($generics:tt)*) => $item:ty) => {
impl $($generics)* Iterator for $name $($generics)* {
Expand Down

0 comments on commit 9984a31

Please sign in to comment.