Allow Vecs, BTreeMaps, and HashMaps to be deserialized from a unit

Closes #36
This commit is contained in:
Erick Tryzelaar
2015-03-20 08:47:33 -07:00
parent d17846eff1
commit 09de237033
3 changed files with 58 additions and 2 deletions
+21
View File
@@ -659,6 +659,13 @@ impl<T> VecVisitor<T> {
impl<T> Visitor for VecVisitor<T> where T: Deserialize {
type Value = Vec<T>;
#[inline]
fn visit_unit<E>(&mut self) -> Result<Vec<T>, E>
where E: Error,
{
Ok(vec![])
}
#[inline]
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<Vec<T>, V::Error>
where V: SeqVisitor,
@@ -767,6 +774,13 @@ impl<K, V> Visitor for HashMapVisitor<K, V>
{
type Value = HashMap<K, V>;
#[inline]
fn visit_unit<E>(&mut self) -> Result<HashMap<K, V>, E>
where E: Error,
{
Ok(HashMap::new())
}
#[inline]
fn visit_map<V_>(&mut self, mut visitor: V_) -> Result<HashMap<K, V>, V_::Error>
where V_: MapVisitor,
@@ -816,6 +830,13 @@ impl<K, V> Visitor for BTreeMapVisitor<K, V>
{
type Value = BTreeMap<K, V>;
#[inline]
fn visit_unit<E>(&mut self) -> Result<BTreeMap<K, V>, E>
where E: Error,
{
Ok(BTreeMap::new())
}
#[inline]
fn visit_map<Visitor>(&mut self, mut visitor: Visitor) -> Result<BTreeMap<K, V>, Visitor::Error>
where Visitor: MapVisitor,