mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-25 23:21:04 +00:00
Remove SeqVisitor::end() and MapVisitor::end()
This commit is contained in:
@@ -199,8 +199,6 @@ mod bytebuf {
|
||||
values.push(value);
|
||||
}
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok(ByteBuf::from(values))
|
||||
}
|
||||
|
||||
|
||||
+3
-20
@@ -88,10 +88,10 @@ impl Visitor for UnitVisitor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<(), V::Error>
|
||||
fn visit_seq<V>(&mut self, _: V) -> Result<(), V::Error>
|
||||
where V: SeqVisitor,
|
||||
{
|
||||
visitor.end()
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -433,8 +433,6 @@ macro_rules! seq_impl {
|
||||
$insert(&mut values, value);
|
||||
}
|
||||
|
||||
try!($visitor.end());
|
||||
|
||||
Ok(values)
|
||||
}
|
||||
}
|
||||
@@ -540,10 +538,9 @@ impl<T> Visitor for ArrayVisitor<[T; 0]> where T: Deserialize {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<V>(&mut self, mut visitor: V) -> Result<[T; 0], V::Error>
|
||||
fn visit_seq<V>(&mut self, _: V) -> Result<[T; 0], V::Error>
|
||||
where V: SeqVisitor,
|
||||
{
|
||||
try!(visitor.end());
|
||||
Ok([])
|
||||
}
|
||||
}
|
||||
@@ -575,8 +572,6 @@ macro_rules! array_impls {
|
||||
};
|
||||
)+
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok([$($name),+])
|
||||
}
|
||||
}
|
||||
@@ -661,8 +656,6 @@ macro_rules! tuple_impls {
|
||||
};
|
||||
)+
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok(($($name,)+))
|
||||
}
|
||||
}
|
||||
@@ -746,8 +739,6 @@ macro_rules! map_impl {
|
||||
values.insert(key, value);
|
||||
}
|
||||
|
||||
try!($visitor.end());
|
||||
|
||||
Ok(values)
|
||||
}
|
||||
}
|
||||
@@ -1034,18 +1025,15 @@ impl Deserialize for Duration {
|
||||
let secs: u64 = match try!(visitor.visit()) {
|
||||
Some(value) => value,
|
||||
None => {
|
||||
try!(visitor.end());
|
||||
return Err(Error::invalid_length(0));
|
||||
}
|
||||
};
|
||||
let nanos: u32 = match try!(visitor.visit()) {
|
||||
Some(value) => value,
|
||||
None => {
|
||||
try!(visitor.end());
|
||||
return Err(Error::invalid_length(1));
|
||||
}
|
||||
};
|
||||
try!(visitor.end());
|
||||
Ok(Duration::new(secs, nanos))
|
||||
}
|
||||
|
||||
@@ -1070,7 +1058,6 @@ impl Deserialize for Duration {
|
||||
}
|
||||
}
|
||||
}
|
||||
try!(visitor.end());
|
||||
let secs = match secs {
|
||||
Some(secs) => secs,
|
||||
None => try!(visitor.missing_field("secs")),
|
||||
@@ -1274,8 +1261,6 @@ impl Deserialize for IgnoredAny {
|
||||
while let Some(_) = try!(visitor.visit::<IgnoredAny>()) {
|
||||
// Gobble
|
||||
}
|
||||
|
||||
try!(visitor.end());
|
||||
Ok(IgnoredAny)
|
||||
}
|
||||
|
||||
@@ -1286,8 +1271,6 @@ impl Deserialize for IgnoredAny {
|
||||
while let Some((_, _)) = try!(visitor.visit::<IgnoredAny, IgnoredAny>()) {
|
||||
// Gobble
|
||||
}
|
||||
|
||||
try!(visitor.end());
|
||||
Ok(IgnoredAny)
|
||||
}
|
||||
|
||||
|
||||
@@ -635,9 +635,6 @@ pub trait SeqVisitor {
|
||||
fn visit<T>(&mut self) -> Result<Option<T>, Self::Error>
|
||||
where T: Deserialize;
|
||||
|
||||
/// This signals to the `SeqVisitor` that the `Visitor` does not expect any more items.
|
||||
fn end(&mut self) -> Result<(), Self::Error>;
|
||||
|
||||
/// Return the lower and upper bound of items remaining in the sequence.
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
@@ -655,11 +652,6 @@ impl<'a, V> SeqVisitor for &'a mut V where V: SeqVisitor {
|
||||
(**self).visit()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn end(&mut self) -> Result<(), V::Error> {
|
||||
(**self).end()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(**self).size_hint()
|
||||
@@ -700,9 +692,6 @@ pub trait MapVisitor {
|
||||
fn visit_value<V>(&mut self) -> Result<V, Self::Error>
|
||||
where V: Deserialize;
|
||||
|
||||
/// This signals to the `MapVisitor` that the `Visitor` does not expect any more items.
|
||||
fn end(&mut self) -> Result<(), Self::Error>;
|
||||
|
||||
/// Return the lower and upper bound of items remaining in the sequence.
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
@@ -742,11 +731,6 @@ impl<'a, V_> MapVisitor for &'a mut V_ where V_: MapVisitor {
|
||||
(**self).visit_value()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn end(&mut self) -> Result<(), V_::Error> {
|
||||
(**self).end()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(**self).size_hint()
|
||||
|
||||
+33
-35
@@ -41,7 +41,7 @@ use error;
|
||||
use core::fmt;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use de;
|
||||
use de::{self, SeqVisitor};
|
||||
use bytes;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -543,7 +543,12 @@ impl<I, T, E> de::Deserializer for SeqDeserializer<I, E>
|
||||
fn deserialize<V>(&mut self, mut visitor: V) -> Result<V::Value, Self::Error>
|
||||
where V: de::Visitor,
|
||||
{
|
||||
visitor.visit_seq(self)
|
||||
let v = try!(visitor.visit_seq(&mut *self));
|
||||
if self.len == 0 {
|
||||
Ok(v)
|
||||
} else {
|
||||
Err(de::Error::invalid_length(self.len))
|
||||
}
|
||||
}
|
||||
|
||||
forward_to_deserialize! {
|
||||
@@ -573,14 +578,6 @@ impl<I, T, E> de::SeqVisitor for SeqDeserializer<I, E>
|
||||
}
|
||||
}
|
||||
|
||||
fn end(&mut self) -> Result<(), Self::Error> {
|
||||
if self.len == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(de::Error::invalid_length(self.len))
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.len, Some(self.len))
|
||||
}
|
||||
@@ -715,6 +712,13 @@ impl<I, K, V, E> MapDeserializer<I, K, V, E>
|
||||
(k, v)
|
||||
})
|
||||
}
|
||||
|
||||
fn end(&mut self) -> Result<(), E> {
|
||||
match self.len {
|
||||
Some(len) if len > 0 => Err(de::Error::invalid_length(len)),
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, K, V, E> de::Deserializer for MapDeserializer<I, K, V, E>
|
||||
@@ -728,22 +732,29 @@ impl<I, K, V, E> de::Deserializer for MapDeserializer<I, K, V, E>
|
||||
fn deserialize<V_>(&mut self, mut visitor: V_) -> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor,
|
||||
{
|
||||
visitor.visit_map(self)
|
||||
let value = try!(visitor.visit_map(&mut *self));
|
||||
try!(self.end());
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_seq<V_>(&mut self, mut visitor: V_) -> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor,
|
||||
{
|
||||
visitor.visit_seq(self)
|
||||
let value = try!(visitor.visit_seq(&mut *self));
|
||||
try!(self.end());
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
fn deserialize_seq_fixed_size<V_>(&mut self, len: usize, mut visitor: V_) -> Result<V_::Value, Self::Error>
|
||||
where V_: de::Visitor,
|
||||
{
|
||||
match self.len {
|
||||
Some(map_len) if map_len == len => visitor.visit_seq(self),
|
||||
Some(_) => Err(de::Error::invalid_length(len)),
|
||||
None => visitor.visit_seq(self),
|
||||
Some(map_len) if map_len != len => Err(de::Error::invalid_length(len)),
|
||||
_ => {
|
||||
let value = try!(visitor.visit_seq(&mut *self));
|
||||
try!(self.end());
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,13 +800,6 @@ impl<I, K, V, E> de::MapVisitor for MapDeserializer<I, K, V, E>
|
||||
}
|
||||
}
|
||||
|
||||
fn end(&mut self) -> Result<(), Self::Error> {
|
||||
match self.len {
|
||||
Some(len) if len > 0 => Err(de::Error::invalid_length(len)),
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.len.map_or_else(
|
||||
|| self.iter.size_hint(),
|
||||
@@ -823,10 +827,6 @@ impl<I, K, V, E> de::SeqVisitor for MapDeserializer<I, K, V, E>
|
||||
}
|
||||
}
|
||||
|
||||
fn end(&mut self) -> Result<(), Self::Error> {
|
||||
de::MapVisitor::end(self)
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
de::MapVisitor::size_hint(self)
|
||||
}
|
||||
@@ -860,7 +860,13 @@ impl<A, B, E> de::Deserializer for PairDeserializer<A, B, E>
|
||||
{
|
||||
match self.0.take() {
|
||||
Some((k, v)) => {
|
||||
visitor.visit_seq(PairVisitor(Some(k), Some(v), PhantomData))
|
||||
let mut pair_visitor = PairVisitor(Some(k), Some(v), PhantomData);
|
||||
let pair = try!(visitor.visit_seq(&mut pair_visitor));
|
||||
if pair_visitor.1.is_none() {
|
||||
Ok(pair)
|
||||
} else {
|
||||
Err(de::Error::invalid_length(pair_visitor.size_hint().0))
|
||||
}
|
||||
}
|
||||
None => Err(de::Error::end_of_stream()),
|
||||
}
|
||||
@@ -900,14 +906,6 @@ impl<A, B, E> de::SeqVisitor for PairVisitor<A, B, E>
|
||||
}
|
||||
}
|
||||
|
||||
fn end(&mut self) -> Result<(), Self::Error> {
|
||||
if self.1.is_none() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(de::Error::invalid_length(self.size_hint().0))
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let len = if self.0.is_some() {
|
||||
2
|
||||
|
||||
Reference in New Issue
Block a user