Add Serializer
hooks for sequence elements
This commit is contained in:
parent
92029a05c6
commit
236d40d73e
@ -339,7 +339,7 @@ macro_rules! tuple_impls {
|
||||
$(
|
||||
$state => {
|
||||
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]
|
||||
fn serialize<S: Serializer>(&self, serializer: &mut S) -> Result<(), S::Error> {
|
||||
serializer.visit_seq($TupleVisitor::new(self))
|
||||
serializer.visit_tuple($TupleVisitor::new(self))
|
||||
}
|
||||
}
|
||||
)+
|
||||
|
@ -132,13 +132,37 @@ pub trait Serializer {
|
||||
fn visit_seq<V>(&mut self, visitor: V) -> Result<(), Self::Error>
|
||||
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]
|
||||
fn visit_named_seq<V>(&mut self,
|
||||
_name: &'static str,
|
||||
visitor: V) -> Result<(), Self::Error>
|
||||
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]
|
||||
@ -148,15 +172,23 @@ pub trait Serializer {
|
||||
visitor: V) -> Result<(), Self::Error>
|
||||
where V: SeqVisitor,
|
||||
{
|
||||
self.visit_seq(visitor)
|
||||
self.visit_tuple(visitor)
|
||||
}
|
||||
|
||||
fn visit_seq_elt<T>(&mut self, value: T) -> Result<(), Self::Error>
|
||||
where T: Serialize;
|
||||
#[inline]
|
||||
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>
|
||||
where V: MapVisitor;
|
||||
|
||||
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
||||
where K: Serialize,
|
||||
V: Serialize;
|
||||
|
||||
#[inline]
|
||||
fn visit_named_map<V>(&mut self,
|
||||
_name: &'static str,
|
||||
@ -167,18 +199,30 @@ pub trait Serializer {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_enum_map<V>(&mut self,
|
||||
_name: &'static str,
|
||||
_variant: &'static str,
|
||||
visitor: V) -> Result<(), Self::Error>
|
||||
where V: MapVisitor,
|
||||
fn visit_named_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
|
||||
where K: Serialize,
|
||||
V: Serialize,
|
||||
{
|
||||
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,
|
||||
V: Serialize;
|
||||
V: Serialize,
|
||||
{
|
||||
self.visit_named_map_elt(key, value)
|
||||
}
|
||||
|
||||
/// Specify a format string for the serializer.
|
||||
///
|
||||
|
@ -476,7 +476,7 @@ fn serialize_tuple_struct_visitor(
|
||||
quote_arm!(cx,
|
||||
$i => {
|
||||
self.state += 1;
|
||||
let v = try!(serializer.visit_seq_elt(&$expr));
|
||||
let v = try!(serializer.visit_named_seq_elt(&$expr));
|
||||
Ok(Some(v))
|
||||
}
|
||||
)
|
||||
@ -559,7 +559,7 @@ fn serialize_struct_visitor<I>(
|
||||
Ok(
|
||||
Some(
|
||||
try!(
|
||||
serializer.visit_map_elt(
|
||||
serializer.visit_named_map_elt(
|
||||
$key_expr,
|
||||
$value_expr,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user