diff --git a/src/libserialize/collection_impls.rs b/src/libserialize/collection_impls.rs index d2d1f5fa8b0..ffeb190ddf8 100644 --- a/src/libserialize/collection_impls.rs +++ b/src/libserialize/collection_impls.rs @@ -16,7 +16,7 @@ use std::hash::{Hash, Hasher}; use {Decodable, Encodable, Decoder, Encoder}; use std::collections::{DList, RingBuf, TreeMap, TreeSet, HashMap, HashSet, - TrieMap, TrieSet}; + TrieMap, TrieSet, VecMap}; use std::collections::enum_set::{EnumSet, CLike}; impl< @@ -311,3 +311,37 @@ impl> Decodable for TrieSet { }) } } + +impl< + E, + S: Encoder, + V: Encodable +> Encodable for VecMap { + fn encode(&self, e: &mut S) -> Result<(), E> { + e.emit_map(self.len(), |e| { + for (i, (key, val)) in self.iter().enumerate() { + try!(e.emit_map_elt_key(i, |e| key.encode(e))); + try!(e.emit_map_elt_val(i, |e| val.encode(e))); + } + Ok(()) + }) + } +} + +impl< + E, + D: Decoder, + V: Decodable +> Decodable for VecMap { + fn decode(d: &mut D) -> Result, E> { + d.read_map(|d, len| { + let mut map = VecMap::new(); + for i in range(0u, len) { + let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d))); + let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d))); + map.insert(key, val); + } + Ok(map) + }) + } +}