Change ser::{Seq,Map}Visitor to return an optional exact length

This is necessary for formats that serialize the length in the
format stream. Those formats need the exact length, so the
iterator-style size_hint has the wrong semantics.
This commit is contained in:
Erick Tryzelaar
2015-03-12 19:40:46 -07:00
parent 9e454a243a
commit 5dd53e7ea3
4 changed files with 63 additions and 61 deletions
+1 -5
View File
@@ -233,11 +233,7 @@ impl ser::Serializer for Serializer {
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<(), ()>
where V: ser::SeqVisitor,
{
let len = match visitor.size_hint() {
(_, Some(len)) => len,
(len, None) => len,
};
let len = visitor.len().unwrap_or(0);
let values = Vec::with_capacity(len);
self.state.push(State::Array(values));