mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 23:01:01 +00:00
Add Serializer hooks for sequence elements
This commit is contained in:
@@ -339,7 +339,7 @@ macro_rules! tuple_impls {
|
|||||||
$(
|
$(
|
||||||
$state => {
|
$state => {
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
Ok(Some(try!(serializer.visit_seq_elt(&e!(self.tuple.$idx)))))
|
Ok(Some(try!(serializer.visit_tuple_elt(&e!(self.tuple.$idx)))))
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
_ => {
|
_ => {
|
||||||
@@ -358,7 +358,7 @@ macro_rules! tuple_impls {
|
|||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
|
fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
|
||||||
serializer.visit_seq($TupleVisitor::new(self))
|
serializer.visit_tuple($TupleVisitor::new(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)+
|
)+
|
||||||
|
|||||||
+56
-12
@@ -132,13 +132,37 @@ pub trait Serializer {
|
|||||||
fn visit_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
fn visit_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
||||||
where V: SeqVisitor;
|
where V: SeqVisitor;
|
||||||
|
|
||||||
|
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||||
|
where T: Serialize;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_tuple<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
||||||
|
where V: SeqVisitor,
|
||||||
|
{
|
||||||
|
self.visit_seq(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_tuple_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||||
|
where T: Serialize
|
||||||
|
{
|
||||||
|
self.visit_seq_elt(value)
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_named_seq<V>(&mut self,
|
fn visit_named_seq<V>(&mut self,
|
||||||
_name: &'static str,
|
_name: &'static str,
|
||||||
visitor: V) -> Result<(), Self::Error>
|
visitor: V) -> Result<(), Self::Error>
|
||||||
where V: SeqVisitor,
|
where V: SeqVisitor,
|
||||||
{
|
{
|
||||||
self.visit_seq(visitor)
|
self.visit_tuple(visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_named_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||||
|
where T: Serialize
|
||||||
|
{
|
||||||
|
self.visit_tuple_elt(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -148,15 +172,23 @@ pub trait Serializer {
|
|||||||
visitor: V) -> Result<(), Self::Error>
|
visitor: V) -> Result<(), Self::Error>
|
||||||
where V: SeqVisitor,
|
where V: SeqVisitor,
|
||||||
{
|
{
|
||||||
self.visit_seq(visitor)
|
self.visit_tuple(visitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
#[inline]
|
||||||
where T: Serialize;
|
fn visit_enum_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||||
|
where T: Serialize
|
||||||
|
{
|
||||||
|
self.visit_tuple_elt(value)
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_map<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
fn visit_map<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
||||||
where V: MapVisitor;
|
where V: MapVisitor;
|
||||||
|
|
||||||
|
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
||||||
|
where K: Serialize,
|
||||||
|
V: Serialize;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_named_map<V>(&mut self,
|
fn visit_named_map<V>(&mut self,
|
||||||
_name: &'static str,
|
_name: &'static str,
|
||||||
@@ -167,18 +199,30 @@ pub trait Serializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_enum_map<V>(&mut self,
|
fn visit_named_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
||||||
_name: &'static str,
|
where K: Serialize,
|
||||||
_variant: &'static str,
|
V: Serialize,
|
||||||
visitor: V) -> Result<(), Self::Error>
|
|
||||||
where V: MapVisitor,
|
|
||||||
{
|
{
|
||||||
self.visit_map(visitor)
|
self.visit_map_elt(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
#[inline]
|
||||||
|
fn visit_enum_map<V>(&mut self,
|
||||||
|
_name: &'static str,
|
||||||
|
variant: &'static str,
|
||||||
|
visitor: V) -> Result<(), Self::Error>
|
||||||
|
where V: MapVisitor,
|
||||||
|
{
|
||||||
|
self.visit_named_map(variant, visitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn visit_enum_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
||||||
where K: Serialize,
|
where K: Serialize,
|
||||||
V: Serialize;
|
V: Serialize,
|
||||||
|
{
|
||||||
|
self.visit_named_map_elt(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
/// Specify a format string for the serializer.
|
/// Specify a format string for the serializer.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ fn serialize_tuple_struct_visitor(
|
|||||||
quote_arm!(cx,
|
quote_arm!(cx,
|
||||||
$i => {
|
$i => {
|
||||||
self.state += 1;
|
self.state += 1;
|
||||||
let v = try!(serializer.visit_seq_elt(&$expr));
|
let v = try!(serializer.visit_named_seq_elt(&$expr));
|
||||||
Ok(Some(v))
|
Ok(Some(v))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -559,7 +559,7 @@ fn serialize_struct_visitor<I>(
|
|||||||
Ok(
|
Ok(
|
||||||
Some(
|
Some(
|
||||||
try!(
|
try!(
|
||||||
serializer.visit_map_elt(
|
serializer.visit_named_map_elt(
|
||||||
$key_expr,
|
$key_expr,
|
||||||
$value_expr,
|
$value_expr,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user