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
+6 -8
View File
@@ -265,9 +265,8 @@ fn serialize_tuple_struct(
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let size = $len - (self.state as usize);
(size, Some(size))
fn len(&self) -> Option<usize> {
Some($len)
}
}
@@ -349,9 +348,8 @@ fn serialize_struct(
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let size = $len - (self.state as usize);
(size, Some(size))
fn len(&self) -> Option<usize> {
Some($len)
}
}
@@ -550,8 +548,8 @@ fn serialize_variant(
ast::MethodImplItem(
quote_method!(cx,
fn size_hint(&self) -> (usize, Option<usize>) {
($len - self.state as usize, Some($len - self.state as usize))
fn len(&self) -> Option<usize> {
Some($len)
}
)
),