json needs more info
This commit is contained in:
parent
fb575225bc
commit
6adcaa55e5
@ -156,7 +156,7 @@ impl<T> Serialize for [T]
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ macro_rules! array_impls {
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -227,7 +227,7 @@ impl<T> Serialize for BinaryHeap<T>
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,7 @@ impl<T> Serialize for BTreeSet<T>
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,7 +259,7 @@ impl<T> Serialize for EnumSet<T>
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ impl<T, H> Serialize for HashSet<T, H>
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ impl<T> Serialize for LinkedList<T>
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -333,7 +333,7 @@ impl<T> Serialize for VecDeque<T> where T: Serialize {
|
||||
for e in self.iter() {
|
||||
try!(serializer.serialize_seq_elt(e));
|
||||
}
|
||||
serializer.serialize_seq_end()
|
||||
serializer.serialize_seq_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,7 +373,7 @@ macro_rules! tuple_impls {
|
||||
$(
|
||||
try!(serializer.serialize_tuple_elt(&e!(self.$idx)));
|
||||
)+
|
||||
serializer.serialize_tuple_end()
|
||||
serializer.serialize_tuple_end($len)
|
||||
}
|
||||
}
|
||||
)+
|
||||
@ -566,7 +566,7 @@ impl<K, V> Serialize for BTreeMap<K, V>
|
||||
for (k, v) in self.iter() {
|
||||
try!(serializer.serialize_map_elt(k, v));
|
||||
}
|
||||
serializer.serialize_map_end()
|
||||
serializer.serialize_map_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -584,7 +584,7 @@ impl<K, V, H> Serialize for HashMap<K, V, H>
|
||||
for (k, v) in self.iter() {
|
||||
try!(serializer.serialize_map_elt(k, v));
|
||||
}
|
||||
serializer.serialize_map_end()
|
||||
serializer.serialize_map_end(Some(self.len()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ pub trait Serializer {
|
||||
for b in value.iter() {
|
||||
try!(self.serialize_seq_elt(b));
|
||||
}
|
||||
self.serialize_seq_end()
|
||||
self.serialize_seq_end(Some(value.len()))
|
||||
}
|
||||
|
||||
/// Serializes a `()` value.
|
||||
@ -176,7 +176,7 @@ pub trait Serializer {
|
||||
{
|
||||
try!(self.serialize_tuple_struct(name, 1));
|
||||
try!(self.serialize_tuple_struct_elt(value));
|
||||
self.serialize_tuple_struct_end()
|
||||
self.serialize_tuple_struct_end(name, 1)
|
||||
}
|
||||
|
||||
/// Allows a variant with a single item to be more efficiently
|
||||
@ -192,7 +192,7 @@ pub trait Serializer {
|
||||
{
|
||||
try!(self.serialize_tuple_variant(name, variant_index, variant, 1));
|
||||
try!(self.serialize_tuple_variant_elt(value));
|
||||
self.serialize_tuple_variant_end()
|
||||
self.serialize_tuple_variant_end(name, variant_index, variant, 1)
|
||||
}
|
||||
|
||||
/// Serializes a `None` value..serialize
|
||||
@ -213,7 +213,7 @@ pub trait Serializer {
|
||||
where T: Serialize;
|
||||
|
||||
/// Finish serializing a sequence.
|
||||
fn serialize_seq_end(&mut self) -> Result<(), Self::Error>;
|
||||
fn serialize_seq_end(&mut self, len: Option<usize>) -> Result<(), Self::Error>;
|
||||
|
||||
/// Serializes a tuple.
|
||||
///
|
||||
@ -237,8 +237,8 @@ pub trait Serializer {
|
||||
///
|
||||
/// By default, tuples are serialized as a sequence.
|
||||
#[inline]
|
||||
fn serialize_tuple_end(&mut self) -> Result<(), Self::Error> {
|
||||
self.serialize_seq_end()
|
||||
fn serialize_tuple_end(&mut self, len: usize) -> Result<(), Self::Error> {
|
||||
self.serialize_seq_end(Some(len))
|
||||
}
|
||||
|
||||
/// Serializes a fixed-size array.
|
||||
@ -276,8 +276,11 @@ pub trait Serializer {
|
||||
///
|
||||
/// By default, tuple structs are serialized as a sequence.
|
||||
#[inline]
|
||||
fn serialize_tuple_struct_end(&mut self) -> Result<(), Self::Error> {
|
||||
self.serialize_tuple_end()
|
||||
fn serialize_tuple_struct_end(&mut self,
|
||||
_name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.serialize_tuple_end(len)
|
||||
}
|
||||
|
||||
/// Serializes a tuple variant.
|
||||
@ -301,15 +304,20 @@ pub trait Serializer {
|
||||
fn serialize_tuple_variant_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||
where T: Serialize
|
||||
{
|
||||
self.serialize_tuple_elt(value)
|
||||
self.serialize_tuple_struct_elt(value)
|
||||
}
|
||||
|
||||
/// Finishes serialization of a tuple variant.
|
||||
///
|
||||
/// By default, tuple variants are serialized as tuples.
|
||||
#[inline]
|
||||
fn serialize_tuple_variant_end(&mut self) -> Result<(), Self::Error> {
|
||||
self.serialize_tuple_end()
|
||||
fn serialize_tuple_variant_end(&mut self,
|
||||
_name: &'static str,
|
||||
_variant_index: usize,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.serialize_tuple_struct_end(variant, len)
|
||||
}
|
||||
|
||||
/// Serialize a map.
|
||||
@ -319,16 +327,16 @@ pub trait Serializer {
|
||||
fn serialize_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error> where K: Serialize, V: Serialize;
|
||||
|
||||
/// Finishes serializing a map
|
||||
fn serialize_map_end(&mut self) -> Result<(), Self::Error>;
|
||||
fn serialize_map_end(&mut self, len: Option<usize>) -> Result<(), Self::Error>;
|
||||
|
||||
/// Serializes a struct.
|
||||
///
|
||||
/// By default, structs are serialized as a map with the field name as the key.
|
||||
#[inline]
|
||||
fn serialize_struct(&mut self,
|
||||
_name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error>
|
||||
_name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error>
|
||||
{
|
||||
self.serialize_map(Some(len))
|
||||
}
|
||||
@ -343,8 +351,11 @@ pub trait Serializer {
|
||||
/// Finishes serializing a struct
|
||||
///
|
||||
/// By default, structs are serialized as a map with the field name as the key.
|
||||
fn serialize_struct_end(&mut self) -> Result<(), Self::Error> {
|
||||
self.serialize_map_end()
|
||||
fn serialize_struct_end(&mut self,
|
||||
_name: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.serialize_map_end(Some(len))
|
||||
}
|
||||
|
||||
/// Serializes a struct variant.
|
||||
@ -371,7 +382,12 @@ pub trait Serializer {
|
||||
/// Finishes serializing a struct variant
|
||||
///
|
||||
/// By default, structs are serialized as a map with the field name as the key.
|
||||
fn serialize_struct_variant_end(&mut self) -> Result<(), Self::Error> {
|
||||
self.serialize_struct_end()
|
||||
fn serialize_struct_variant_end(&mut self,
|
||||
_name: &'static str,
|
||||
_variant_index: usize,
|
||||
variant: &'static str,
|
||||
len: usize,
|
||||
) -> Result<(), Self::Error> {
|
||||
self.serialize_struct_end(variant, len)
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ fn serialize_tuple_struct(
|
||||
quote_expr!(cx, {
|
||||
try!(_serializer.serialize_tuple_struct($type_name, $len));
|
||||
$serialize_stmts
|
||||
_serializer.serialize_tuple_struct_end()
|
||||
_serializer.serialize_tuple_struct_end($type_name, $len)
|
||||
})
|
||||
}
|
||||
|
||||
@ -269,9 +269,10 @@ fn serialize_struct(
|
||||
.fold(quote_expr!(cx, 0), |sum, expr| quote_expr!(cx, $sum + $expr));
|
||||
|
||||
quote_expr!(cx, {
|
||||
try!(_serializer.serialize_struct($type_name, $len));
|
||||
let len = $len;
|
||||
try!(_serializer.serialize_struct($type_name, len));
|
||||
$serialize_fields
|
||||
_serializer.serialize_struct_end()
|
||||
_serializer.serialize_struct_end($type_name, len)
|
||||
})
|
||||
}
|
||||
|
||||
@ -465,7 +466,7 @@ fn serialize_tuple_variant(
|
||||
quote_expr!(cx, {
|
||||
try!(_serializer.serialize_tuple_variant($type_name, $variant_index, $variant_name, $len));
|
||||
$serialize_stmts
|
||||
_serializer.serialize_tuple_variant_end()
|
||||
_serializer.serialize_tuple_variant_end($type_name, $variant_index, $variant_name, $len)
|
||||
})
|
||||
}
|
||||
|
||||
@ -505,14 +506,20 @@ fn serialize_struct_variant(
|
||||
.fold(quote_expr!(cx, 0), |sum, expr| quote_expr!(cx, $sum + $expr));
|
||||
|
||||
quote_expr!(cx, {
|
||||
let len = $len;
|
||||
try!(_serializer.serialize_struct_variant(
|
||||
$item_name,
|
||||
$variant_index,
|
||||
$variant_name,
|
||||
$len,
|
||||
len,
|
||||
));
|
||||
$serialize_fields
|
||||
_serializer.serialize_struct_variant_end()
|
||||
_serializer.serialize_struct_variant_end(
|
||||
$item_name,
|
||||
$variant_index,
|
||||
$variant_name,
|
||||
len,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_seq_end(&mut self) -> Result<(), Error> {
|
||||
fn serialize_seq_end(&mut self, _len: Option<usize>) -> Result<(), Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::SeqEnd));
|
||||
Ok(())
|
||||
}
|
||||
@ -189,7 +189,7 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_tuple_end(&mut self) -> Result<(), Error> {
|
||||
fn serialize_tuple_end(&mut self, _len: usize) -> Result<(), Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::TupleEnd));
|
||||
Ok(())
|
||||
}
|
||||
@ -217,12 +217,12 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct_end(&mut self) -> Result<(), Error> {
|
||||
fn serialize_tuple_struct_end(&mut self, _name: &str, _len: usize) -> Result<(), Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::TupleStructEnd));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant<'b>(&'b mut self,
|
||||
fn serialize_tuple_variant(&mut self,
|
||||
name: &str,
|
||||
_variant_index: usize,
|
||||
variant: &str,
|
||||
@ -240,12 +240,16 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant_end(&mut self) -> Result<(), Error> {
|
||||
fn serialize_tuple_variant_end(&mut self,
|
||||
_name: &str,
|
||||
_variant_index: usize,
|
||||
_variant: &str,
|
||||
_len: usize) -> Result<(), Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::EnumSeqEnd));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_map<'b>(&'b mut self, len: Option<usize>) -> Result<(), Error>
|
||||
fn serialize_map(&mut self, len: Option<usize>) -> Result<(), Error>
|
||||
{
|
||||
assert_eq!(self.tokens.next(), Some(&Token::MapStart(len)));
|
||||
|
||||
@ -258,12 +262,12 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_map_end(&mut self) -> Result<(), Self::Error> {
|
||||
fn serialize_map_end(&mut self, _len: Option<usize>) -> Result<(), Self::Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::MapEnd));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn serialize_struct<'b>(&'b mut self, name: &str, len: usize) -> Result<(), Error>
|
||||
fn serialize_struct(&mut self, name: &str, len: usize) -> Result<(), Error>
|
||||
{
|
||||
assert_eq!(self.tokens.next(), Some(&Token::StructStart(name, len)));
|
||||
|
||||
@ -276,7 +280,7 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_struct_end(&mut self) -> Result<(), Self::Error> {
|
||||
fn serialize_struct_end(&mut self, _name: &str, _len: usize) -> Result<(), Self::Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::StructEnd));
|
||||
Ok(())
|
||||
}
|
||||
@ -298,7 +302,11 @@ impl<'a, I> ser::Serializer for Serializer<'a, I>
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_struct_variant_end(&mut self) -> Result<(), Self::Error> {
|
||||
fn serialize_struct_variant_end(&mut self,
|
||||
_name: &str,
|
||||
_variant_index: usize,
|
||||
_variant: &str,
|
||||
_len: usize) -> Result<(), Self::Error> {
|
||||
assert_eq!(self.tokens.next(), Some(&Token::EnumMapEnd));
|
||||
Ok(())
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl serde::Serializer for BytesSerializer {
|
||||
Err(Error)
|
||||
}
|
||||
|
||||
fn serialize_seq<'a>(&'a mut self, _len: Option<usize>) -> Result<(), Error>
|
||||
fn serialize_seq(&mut self, _len: Option<usize>) -> Result<(), Error>
|
||||
{
|
||||
Err(Error)
|
||||
}
|
||||
@ -106,12 +106,12 @@ impl serde::Serializer for BytesSerializer {
|
||||
Err(Error)
|
||||
}
|
||||
|
||||
fn serialize_seq_end(&mut self) -> Result<(), Error>
|
||||
fn serialize_seq_end(&mut self, _: Option<usize>) -> Result<(), Error>
|
||||
{
|
||||
Err(Error)
|
||||
}
|
||||
|
||||
fn serialize_map<'a>(&mut self, _: Option<usize>) -> Result<(), Error>
|
||||
fn serialize_map(&mut self, _: Option<usize>) -> Result<(), Error>
|
||||
{
|
||||
Err(Error)
|
||||
}
|
||||
@ -123,7 +123,7 @@ impl serde::Serializer for BytesSerializer {
|
||||
Err(Error)
|
||||
}
|
||||
|
||||
fn serialize_map_end(&mut self) -> Result<(), Error>
|
||||
fn serialize_map_end(&mut self, _: Option<usize>) -> Result<(), Error>
|
||||
{
|
||||
Err(Error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user