mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-23 08:18:03 +00:00
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:
@@ -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)
|
||||
}
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user