mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 18:41:01 +00:00
Serialize T by ref
This commit is contained in:
@@ -247,7 +247,7 @@ impl<'a, I> Serialize for Iterator<I>
|
|||||||
};
|
};
|
||||||
let mut seq = try!(serializer.serialize_seq(size));
|
let mut seq = try!(serializer.serialize_seq(size));
|
||||||
for e in iter {
|
for e in iter {
|
||||||
try!(seq.serialize_element(e));
|
try!(seq.serialize_element(&e));
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ macro_rules! serialize_seq {
|
|||||||
{
|
{
|
||||||
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
||||||
for e in self {
|
for e in self {
|
||||||
try!(seq.serialize_element(e));
|
try!(seq.serialize_element(&e));
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ impl<A> Serialize for ops::Range<A>
|
|||||||
{
|
{
|
||||||
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
||||||
for e in self.clone() {
|
for e in self.clone() {
|
||||||
try!(seq.serialize_element(e));
|
try!(seq.serialize_element(&e));
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ impl<A> Serialize for ops::RangeInclusive<A>
|
|||||||
{
|
{
|
||||||
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
let mut seq = try!(serializer.serialize_seq(Some(self.len())));
|
||||||
for e in self.clone() {
|
for e in self.clone() {
|
||||||
try!(seq.serialize_element(e));
|
try!(seq.serialize_element(&e));
|
||||||
}
|
}
|
||||||
seq.end()
|
seq.end()
|
||||||
}
|
}
|
||||||
@@ -696,8 +696,8 @@ impl Serialize for Duration {
|
|||||||
{
|
{
|
||||||
use super::SerializeStruct;
|
use super::SerializeStruct;
|
||||||
let mut state = try!(serializer.serialize_struct("Duration", 2));
|
let mut state = try!(serializer.serialize_struct("Duration", 2));
|
||||||
try!(state.serialize_field("secs", self.as_secs()));
|
try!(state.serialize_field("secs", &self.as_secs()));
|
||||||
try!(state.serialize_field("nanos", self.subsec_nanos()));
|
try!(state.serialize_field("nanos", &self.subsec_nanos()));
|
||||||
state.end()
|
state.end()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-14
@@ -200,30 +200,30 @@ pub trait Serializer {
|
|||||||
/// struct, to be more efficiently serialized than a tuple struct with
|
/// struct, to be more efficiently serialized than a tuple struct with
|
||||||
/// multiple items. A reasonable implementation would be to forward to
|
/// multiple items. A reasonable implementation would be to forward to
|
||||||
/// `serialize_tuple_struct` or to just serialize the inner value without wrapping.
|
/// `serialize_tuple_struct` or to just serialize the inner value without wrapping.
|
||||||
fn serialize_newtype_struct<T: Serialize>(
|
fn serialize_newtype_struct<T: ?Sized + Serialize>(
|
||||||
self,
|
self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
value: T,
|
value: &T,
|
||||||
) -> Result<Self::Ok, Self::Error>;
|
) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Allows a variant with a single item to be more efficiently serialized
|
/// Allows a variant with a single item to be more efficiently serialized
|
||||||
/// than a variant with multiple items. A reasonable implementation would be
|
/// than a variant with multiple items. A reasonable implementation would be
|
||||||
/// to forward to `serialize_tuple_variant`.
|
/// to forward to `serialize_tuple_variant`.
|
||||||
fn serialize_newtype_variant<T: Serialize>(
|
fn serialize_newtype_variant<T: ?Sized + Serialize>(
|
||||||
self,
|
self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
variant_index: usize,
|
variant_index: usize,
|
||||||
variant: &'static str,
|
variant: &'static str,
|
||||||
value: T,
|
value: &T,
|
||||||
) -> Result<Self::Ok, Self::Error>;
|
) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serializes a `None` value.
|
/// Serializes a `None` value.
|
||||||
fn serialize_none(self) -> Result<Self::Ok, Self::Error>;
|
fn serialize_none(self) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Serializes a `Some(...)` value.
|
/// Serializes a `Some(...)` value.
|
||||||
fn serialize_some<T: Serialize>(
|
fn serialize_some<T: ?Sized + Serialize>(
|
||||||
self,
|
self,
|
||||||
value: T,
|
value: &T,
|
||||||
) -> Result<Self::Ok, Self::Error>;
|
) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|
||||||
/// Begins to serialize a sequence. This call must be followed by zero or
|
/// Begins to serialize a sequence. This call must be followed by zero or
|
||||||
@@ -311,7 +311,7 @@ pub trait SerializeSeq {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serializes a sequence element.
|
/// Serializes a sequence element.
|
||||||
fn serialize_element<T: Serialize>(&mut self, value: T) -> Result<(), Self::Error>;
|
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a sequence.
|
/// Finishes serializing a sequence.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -327,7 +327,7 @@ pub trait SerializeTuple {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serializes a tuple element.
|
/// Serializes a tuple element.
|
||||||
fn serialize_element<T: Serialize>(&mut self, value: T) -> Result<(), Self::Error>;
|
fn serialize_element<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a tuple.
|
/// Finishes serializing a tuple.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -343,7 +343,7 @@ pub trait SerializeTupleStruct {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serializes a tuple struct element.
|
/// Serializes a tuple struct element.
|
||||||
fn serialize_field<T: Serialize>(&mut self, value: T) -> Result<(), Self::Error>;
|
fn serialize_field<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a tuple struct.
|
/// Finishes serializing a tuple struct.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -359,7 +359,7 @@ pub trait SerializeTupleVariant {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serializes a tuple variant element.
|
/// Serializes a tuple variant element.
|
||||||
fn serialize_field<T: Serialize>(&mut self, value: T) -> Result<(), Self::Error>;
|
fn serialize_field<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a tuple variant.
|
/// Finishes serializing a tuple variant.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -375,10 +375,10 @@ pub trait SerializeMap {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serialize a map key.
|
/// Serialize a map key.
|
||||||
fn serialize_key<T: Serialize>(&mut self, key: T) -> Result<(), Self::Error>;
|
fn serialize_key<T: ?Sized + Serialize>(&mut self, key: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Serialize a map value.
|
/// Serialize a map value.
|
||||||
fn serialize_value<T: Serialize>(&mut self, value: T) -> Result<(), Self::Error>;
|
fn serialize_value<T: ?Sized + Serialize>(&mut self, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a map.
|
/// Finishes serializing a map.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -394,7 +394,7 @@ pub trait SerializeStruct {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serializes a struct field.
|
/// Serializes a struct field.
|
||||||
fn serialize_field<V: Serialize>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error>;
|
fn serialize_field<T: ?Sized + Serialize>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a struct.
|
/// Finishes serializing a struct.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
@@ -410,7 +410,7 @@ pub trait SerializeStructVariant {
|
|||||||
type Error: Error;
|
type Error: Error;
|
||||||
|
|
||||||
/// Serialize a struct variant element.
|
/// Serialize a struct variant element.
|
||||||
fn serialize_field<V: Serialize>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error>;
|
fn serialize_field<T: ?Sized + Serialize>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error>;
|
||||||
|
|
||||||
/// Finishes serializing a struct variant.
|
/// Finishes serializing a struct variant.
|
||||||
fn end(self) -> Result<Self::Ok, Self::Error>;
|
fn end(self) -> Result<Self::Ok, Self::Error>;
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ fn wrap_serialize_with(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
__SerializeWith {
|
&__SerializeWith {
|
||||||
value: #value,
|
value: #value,
|
||||||
phantom: ::std::marker::PhantomData::<#item_ty>,
|
phantom: ::std::marker::PhantomData::<#item_ty>,
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-18
@@ -139,20 +139,20 @@ impl<'s, 'a, I> ser::Serializer for &'s mut Serializer<'a, I>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_newtype_struct<T>(self,
|
fn serialize_newtype_struct<T: ?Sized>(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
value: T) -> Result<(), Error>
|
value: &T) -> Result<(), Error>
|
||||||
where T: Serialize,
|
where T: Serialize,
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::StructNewType(name)));
|
assert_eq!(self.tokens.next(), Some(&Token::StructNewType(name)));
|
||||||
value.serialize(self)
|
value.serialize(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_newtype_variant<T>(self,
|
fn serialize_newtype_variant<T: ?Sized>(self,
|
||||||
name: &str,
|
name: &str,
|
||||||
_variant_index: usize,
|
_variant_index: usize,
|
||||||
variant: &str,
|
variant: &str,
|
||||||
value: T) -> Result<(), Error>
|
value: &T) -> Result<(), Error>
|
||||||
where T: Serialize,
|
where T: Serialize,
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::EnumNewType(name, variant)));
|
assert_eq!(self.tokens.next(), Some(&Token::EnumNewType(name, variant)));
|
||||||
@@ -164,8 +164,8 @@ impl<'s, 'a, I> ser::Serializer for &'s mut Serializer<'a, I>
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_some<V>(self, value: V) -> Result<(), Error>
|
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<(), Error>
|
||||||
where V: Serialize,
|
where T: Serialize,
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::Option(true)));
|
assert_eq!(self.tokens.next(), Some(&Token::Option(true)));
|
||||||
value.serialize(self)
|
value.serialize(self)
|
||||||
@@ -228,7 +228,7 @@ impl<'s, 'a, I> ser::SerializeSeq for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_element<T>(&mut self, value: T) -> Result<(), Error>
|
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||||
where T: Serialize
|
where T: Serialize
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::SeqSep));
|
assert_eq!(self.tokens.next(), Some(&Token::SeqSep));
|
||||||
@@ -247,7 +247,7 @@ impl<'s, 'a, I> ser::SerializeTuple for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_element<T>(&mut self, value: T) -> Result<(), Error>
|
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||||
where T: Serialize
|
where T: Serialize
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::TupleSep));
|
assert_eq!(self.tokens.next(), Some(&Token::TupleSep));
|
||||||
@@ -266,7 +266,7 @@ impl<'s, 'a, I> ser::SerializeTupleStruct for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_field<T>(&mut self, value: T) -> Result<(), Error>
|
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||||
where T: Serialize
|
where T: Serialize
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::TupleStructSep));
|
assert_eq!(self.tokens.next(), Some(&Token::TupleStructSep));
|
||||||
@@ -285,7 +285,7 @@ impl<'s, 'a, I> ser::SerializeTupleVariant for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_field<T>(&mut self, value: T) -> Result<(), Error>
|
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<(), Error>
|
||||||
where T: Serialize
|
where T: Serialize
|
||||||
{
|
{
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::EnumSeqSep));
|
assert_eq!(self.tokens.next(), Some(&Token::EnumSeqSep));
|
||||||
@@ -304,12 +304,12 @@ impl<'s, 'a, I> ser::SerializeMap for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_key<T>(&mut self, key: T) -> Result<(), Self::Error> where T: Serialize {
|
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<(), Self::Error> where T: Serialize {
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::MapSep));
|
assert_eq!(self.tokens.next(), Some(&Token::MapSep));
|
||||||
key.serialize(&mut **self)
|
key.serialize(&mut **self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_value<T>(&mut self, value: T) -> Result<(), Self::Error> where T: Serialize {
|
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<(), Self::Error> where T: Serialize {
|
||||||
value.serialize(&mut **self)
|
value.serialize(&mut **self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ impl<'s, 'a, I> ser::SerializeStruct for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_field<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize {
|
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where T: Serialize {
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::StructSep));
|
assert_eq!(self.tokens.next(), Some(&Token::StructSep));
|
||||||
try!(key.serialize(&mut **self));
|
try!(key.serialize(&mut **self));
|
||||||
value.serialize(&mut **self)
|
value.serialize(&mut **self)
|
||||||
@@ -343,7 +343,7 @@ impl<'s, 'a, I> ser::SerializeStructVariant for &'s mut Serializer<'a, I>
|
|||||||
type Ok = ();
|
type Ok = ();
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn serialize_field<V>(&mut self, key: &'static str, value: V) -> Result<(), Self::Error> where V: Serialize {
|
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<(), Self::Error> where T: Serialize {
|
||||||
assert_eq!(self.tokens.next(), Some(&Token::EnumMapSep));
|
assert_eq!(self.tokens.next(), Some(&Token::EnumMapSep));
|
||||||
try!(key.serialize(&mut **self));
|
try!(key.serialize(&mut **self));
|
||||||
value.serialize(&mut **self)
|
value.serialize(&mut **self)
|
||||||
|
|||||||
Reference in New Issue
Block a user