Merge pull request #479 from serde-rs/nestser
Remove unnecessary nesting from generated impls
This commit is contained in:
commit
1c55f58093
@ -76,10 +76,8 @@ fn deserialize_item(
|
||||
#[automatically_derived]
|
||||
impl $impl_generics _serde::de::Deserialize for $ty $where_clause {
|
||||
fn deserialize<__D>(deserializer: &mut __D) -> ::std::result::Result<$ty, __D::Error>
|
||||
where __D: _serde::de::Deserializer,
|
||||
{
|
||||
$body
|
||||
}
|
||||
where __D: _serde::de::Deserializer
|
||||
$body
|
||||
}
|
||||
};
|
||||
).unwrap()
|
||||
@ -136,7 +134,7 @@ fn deserialize_body(
|
||||
item: &Item,
|
||||
impl_generics: &ast::Generics,
|
||||
ty: P<ast::Ty>,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
match item.body {
|
||||
Body::Enum(ref variants) => {
|
||||
deserialize_item_enum(
|
||||
@ -274,10 +272,10 @@ fn deserialize_unit_struct(
|
||||
builder: &aster::AstBuilder,
|
||||
type_ident: Ident,
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let type_name = name_expr(builder, item_attrs.name());
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
struct __Visitor;
|
||||
|
||||
impl _serde::de::Visitor for __Visitor {
|
||||
@ -300,7 +298,7 @@ fn deserialize_unit_struct(
|
||||
}
|
||||
|
||||
deserializer.deserialize_unit_struct($type_name, __Visitor)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_tuple(
|
||||
@ -312,7 +310,7 @@ fn deserialize_tuple(
|
||||
ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let where_clause = &impl_generics.where_clause;
|
||||
|
||||
let (visitor_item, visitor_ty, visitor_expr, visitor_generics) = deserialize_visitor(
|
||||
@ -343,7 +341,7 @@ fn deserialize_tuple(
|
||||
None
|
||||
};
|
||||
|
||||
let visit_seq_expr = deserialize_seq(
|
||||
let visit_seq = deserialize_seq(
|
||||
cx,
|
||||
builder,
|
||||
type_ident,
|
||||
@ -366,7 +364,7 @@ fn deserialize_tuple(
|
||||
deserializer.deserialize_tuple_struct($type_name, $nfields, $visitor_expr))
|
||||
};
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
$visitor_item
|
||||
|
||||
impl $visitor_generics _serde::de::Visitor for $visitor_ty $where_clause {
|
||||
@ -376,14 +374,12 @@ fn deserialize_tuple(
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor,
|
||||
{
|
||||
$visit_seq_expr
|
||||
}
|
||||
where __V: _serde::de::SeqVisitor
|
||||
$visit_seq
|
||||
}
|
||||
|
||||
$dispatch
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_seq(
|
||||
@ -394,7 +390,7 @@ fn deserialize_seq(
|
||||
impl_generics: &ast::Generics,
|
||||
fields: &[Field],
|
||||
is_struct: bool,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let mut index_in_seq = 0usize;
|
||||
let let_values: Vec<_> = fields.iter()
|
||||
.enumerate()
|
||||
@ -461,13 +457,13 @@ fn deserialize_seq(
|
||||
.build()
|
||||
};
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
$let_values
|
||||
|
||||
try!(visitor.end());
|
||||
|
||||
Ok($result)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_newtype_struct(
|
||||
@ -513,7 +509,7 @@ fn deserialize_struct(
|
||||
ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let where_clause = &impl_generics.where_clause;
|
||||
|
||||
let (visitor_item, visitor_ty, visitor_expr, visitor_generics) = deserialize_visitor(
|
||||
@ -528,7 +524,7 @@ fn deserialize_struct(
|
||||
None => builder.path().id(type_ident).build(),
|
||||
};
|
||||
|
||||
let visit_seq_expr = deserialize_seq(
|
||||
let visit_seq = deserialize_seq(
|
||||
cx,
|
||||
builder,
|
||||
type_ident,
|
||||
@ -538,7 +534,7 @@ fn deserialize_struct(
|
||||
true,
|
||||
);
|
||||
|
||||
let (field_visitor, fields_stmt, visit_map_expr) = deserialize_struct_visitor(
|
||||
let (field_visitor, fields_stmt, visit_map) = deserialize_struct_visitor(
|
||||
cx,
|
||||
builder,
|
||||
type_ident,
|
||||
@ -558,7 +554,7 @@ fn deserialize_struct(
|
||||
deserializer.deserialize_struct($type_name, FIELDS, $visitor_expr))
|
||||
};
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
$field_visitor
|
||||
|
||||
$visitor_item
|
||||
@ -568,23 +564,19 @@ fn deserialize_struct(
|
||||
|
||||
#[inline]
|
||||
fn visit_seq<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||
where __V: _serde::de::SeqVisitor,
|
||||
{
|
||||
$visit_seq_expr
|
||||
}
|
||||
where __V: _serde::de::SeqVisitor
|
||||
$visit_seq
|
||||
|
||||
#[inline]
|
||||
fn visit_map<__V>(&mut self, mut visitor: __V) -> ::std::result::Result<$ty, __V::Error>
|
||||
where __V: _serde::de::MapVisitor,
|
||||
{
|
||||
$visit_map_expr
|
||||
}
|
||||
where __V: _serde::de::MapVisitor
|
||||
$visit_map
|
||||
}
|
||||
|
||||
$fields_stmt
|
||||
|
||||
$dispatch
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_item_enum(
|
||||
@ -595,7 +587,7 @@ fn deserialize_item_enum(
|
||||
ty: P<ast::Ty>,
|
||||
variants: &[Variant],
|
||||
item_attrs: &attr::Item
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let where_clause = &impl_generics.where_clause;
|
||||
|
||||
let type_name = name_expr(builder, item_attrs.name());
|
||||
@ -633,7 +625,7 @@ fn deserialize_item_enum(
|
||||
.id("__Field").id(format!("__field{}", i))
|
||||
.build();
|
||||
|
||||
let expr = deserialize_variant(
|
||||
let block = deserialize_variant(
|
||||
cx,
|
||||
builder,
|
||||
type_ident,
|
||||
@ -643,7 +635,7 @@ fn deserialize_item_enum(
|
||||
item_attrs,
|
||||
);
|
||||
|
||||
let arm = quote_arm!(cx, $variant_name => { $expr });
|
||||
let arm = quote_arm!(cx, $variant_name => $block);
|
||||
variant_arms.push(arm);
|
||||
}
|
||||
variant_arms.extend(ignored_arm.into_iter());
|
||||
@ -655,7 +647,7 @@ fn deserialize_item_enum(
|
||||
vec![deserializer_ty_arg(builder)],
|
||||
);
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
$variant_visitor
|
||||
|
||||
$visitor_item
|
||||
@ -675,7 +667,7 @@ fn deserialize_item_enum(
|
||||
$variants_stmt
|
||||
|
||||
deserializer.deserialize_enum($type_name, VARIANTS, $visitor_expr)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_variant(
|
||||
@ -686,15 +678,15 @@ fn deserialize_variant(
|
||||
ty: P<ast::Ty>,
|
||||
variant: &Variant,
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let variant_ident = variant.ident;
|
||||
|
||||
match variant.style {
|
||||
Style::Unit => {
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
try!(visitor.visit_unit());
|
||||
Ok($type_ident::$variant_ident)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
Style::Newtype => {
|
||||
deserialize_newtype_variant(
|
||||
@ -740,7 +732,7 @@ fn deserialize_newtype_variant(
|
||||
variant_ident: Ident,
|
||||
impl_generics: &ast::Generics,
|
||||
field: &Field,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let visit = match field.attrs.deserialize_with() {
|
||||
None => {
|
||||
let field_ty = &field.ty;
|
||||
@ -756,7 +748,9 @@ fn deserialize_newtype_variant(
|
||||
})
|
||||
}
|
||||
};
|
||||
quote_expr!(cx, Ok($type_ident::$variant_ident($visit)))
|
||||
quote_block!(cx, {
|
||||
Ok($type_ident::$variant_ident($visit))
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn deserialize_field_visitor(
|
||||
@ -805,17 +799,15 @@ fn deserialize_field_visitor(
|
||||
let fallthrough_index_arm_expr = if !is_variant && !item_attrs.deny_unknown_fields() {
|
||||
quote_expr!(cx, Ok(__Field::__ignore))
|
||||
} else {
|
||||
quote_expr!(cx, {
|
||||
Err(_serde::de::Error::invalid_value($index_error_msg))
|
||||
})
|
||||
quote_expr!(cx, Err(_serde::de::Error::invalid_value($index_error_msg)))
|
||||
};
|
||||
|
||||
let index_body = quote_expr!(cx,
|
||||
let index_body = quote_block!(cx, {
|
||||
match value {
|
||||
$index_field_arms
|
||||
_ => $fallthrough_index_arm_expr
|
||||
}
|
||||
);
|
||||
}).unwrap();
|
||||
|
||||
// Convert the field names into byte strings.
|
||||
let str_field_names: Vec<_> = field_names.iter()
|
||||
@ -835,12 +827,12 @@ fn deserialize_field_visitor(
|
||||
quote_expr!(cx, Err(_serde::de::Error::$unknown_ident(value)))
|
||||
};
|
||||
|
||||
let str_body = quote_expr!(cx,
|
||||
let str_body = quote_block!(cx, {
|
||||
match value {
|
||||
$str_field_arms
|
||||
_ => $fallthrough_str_arm_expr
|
||||
}
|
||||
);
|
||||
}).unwrap();
|
||||
|
||||
// Convert the field names into byte strings.
|
||||
let bytes_field_names: Vec<_> = field_names.iter()
|
||||
@ -866,12 +858,12 @@ fn deserialize_field_visitor(
|
||||
})
|
||||
};
|
||||
|
||||
let bytes_body = quote_expr!(cx,
|
||||
let bytes_body = quote_block!(cx, {
|
||||
match value {
|
||||
$bytes_field_arms
|
||||
_ => $fallthrough_bytes_arm_expr
|
||||
}
|
||||
);
|
||||
}).unwrap();
|
||||
|
||||
let impl_item = quote_item!(cx,
|
||||
impl _serde::de::Deserialize for __Field {
|
||||
@ -889,22 +881,16 @@ fn deserialize_field_visitor(
|
||||
type Value = __Field;
|
||||
|
||||
fn visit_usize<__E>(&mut self, value: usize) -> ::std::result::Result<__Field, __E>
|
||||
where __E: _serde::de::Error,
|
||||
{
|
||||
$index_body
|
||||
}
|
||||
where __E: _serde::de::Error
|
||||
$index_body
|
||||
|
||||
fn visit_str<__E>(&mut self, value: &str) -> ::std::result::Result<__Field, __E>
|
||||
where __E: _serde::de::Error,
|
||||
{
|
||||
$str_body
|
||||
}
|
||||
where __E: _serde::de::Error
|
||||
$str_body
|
||||
|
||||
fn visit_bytes<__E>(&mut self, value: &[u8]) -> ::std::result::Result<__Field, __E>
|
||||
where __E: _serde::de::Error,
|
||||
{
|
||||
$bytes_body
|
||||
}
|
||||
where __E: _serde::de::Error
|
||||
$bytes_body
|
||||
}
|
||||
|
||||
deserializer.deserialize_struct_field(
|
||||
@ -927,7 +913,7 @@ fn deserialize_struct_visitor(
|
||||
impl_generics: &ast::Generics,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> (Vec<P<ast::Item>>, ast::Stmt, P<ast::Expr>) {
|
||||
) -> (Vec<P<ast::Item>>, ast::Stmt, P<ast::Block>) {
|
||||
let field_exprs = fields.iter()
|
||||
.map(|field| field.attrs.name().deserialize_name())
|
||||
.collect();
|
||||
@ -940,7 +926,7 @@ fn deserialize_struct_visitor(
|
||||
false,
|
||||
);
|
||||
|
||||
let visit_map_expr = deserialize_map(
|
||||
let visit_map = deserialize_map(
|
||||
cx,
|
||||
builder,
|
||||
type_ident,
|
||||
@ -968,7 +954,7 @@ fn deserialize_struct_visitor(
|
||||
const FIELDS: &'static [&'static str] = $fields_expr;
|
||||
).unwrap();
|
||||
|
||||
(field_visitor, fields_stmt, visit_map_expr)
|
||||
(field_visitor, fields_stmt, visit_map)
|
||||
}
|
||||
|
||||
fn deserialize_map(
|
||||
@ -979,7 +965,7 @@ fn deserialize_map(
|
||||
impl_generics: &ast::Generics,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
// Create the field names for the fields.
|
||||
let fields_names = fields.iter()
|
||||
.enumerate()
|
||||
@ -1086,7 +1072,7 @@ fn deserialize_map(
|
||||
)
|
||||
.build();
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
$let_values
|
||||
|
||||
while let Some(key) = try!(visitor.visit_key::<__Field>()) {
|
||||
@ -1102,7 +1088,7 @@ fn deserialize_map(
|
||||
$extract_values
|
||||
|
||||
Ok($result)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
/// This function wraps the expression in `#[serde(deserialize_with="...")]` in
|
||||
|
@ -70,10 +70,8 @@ fn serialize_item(
|
||||
#[automatically_derived]
|
||||
impl $impl_generics _serde::ser::Serialize for $ty $where_clause {
|
||||
fn serialize<__S>(&self, _serializer: &mut __S) -> ::std::result::Result<(), __S::Error>
|
||||
where __S: _serde::ser::Serializer,
|
||||
{
|
||||
$body
|
||||
}
|
||||
where __S: _serde::ser::Serializer
|
||||
$body
|
||||
}
|
||||
};
|
||||
).unwrap()
|
||||
@ -119,7 +117,7 @@ fn serialize_body(
|
||||
item: &Item,
|
||||
impl_generics: &ast::Generics,
|
||||
ty: P<ast::Ty>,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
match item.body {
|
||||
Body::Enum(ref variants) => {
|
||||
serialize_item_enum(
|
||||
@ -179,12 +177,12 @@ fn serialize_unit_struct(
|
||||
cx: &ExtCtxt,
|
||||
builder: &aster::AstBuilder,
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let type_name = name_expr(builder, item_attrs.name());
|
||||
|
||||
quote_expr!(cx,
|
||||
quote_block!(cx, {
|
||||
_serializer.serialize_unit_struct($type_name)
|
||||
)
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_newtype_struct(
|
||||
@ -194,7 +192,7 @@ fn serialize_newtype_struct(
|
||||
item_ty: P<ast::Ty>,
|
||||
field: &Field,
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let type_name = name_expr(builder, item_attrs.name());
|
||||
|
||||
let mut field_expr = quote_expr!(cx, &self.0);
|
||||
@ -203,9 +201,9 @@ fn serialize_newtype_struct(
|
||||
&item_ty, impl_generics, &field.ty, path, field_expr);
|
||||
}
|
||||
|
||||
quote_expr!(cx,
|
||||
quote_block!(cx, {
|
||||
_serializer.serialize_newtype_struct($type_name, $field_expr)
|
||||
)
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct(
|
||||
@ -215,7 +213,7 @@ fn serialize_tuple_struct(
|
||||
ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let serialize_stmts = serialize_tuple_struct_visitor(
|
||||
cx,
|
||||
builder,
|
||||
@ -229,11 +227,11 @@ fn serialize_tuple_struct(
|
||||
let type_name = name_expr(builder, item_attrs.name());
|
||||
let len = serialize_stmts.len();
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
let mut state = try!(_serializer.serialize_tuple_struct($type_name, $len));
|
||||
$serialize_stmts
|
||||
_serializer.serialize_tuple_struct_end(state)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_struct(
|
||||
@ -243,7 +241,7 @@ fn serialize_struct(
|
||||
ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let serialize_fields = serialize_struct_visitor(
|
||||
cx,
|
||||
builder,
|
||||
@ -268,11 +266,11 @@ fn serialize_struct(
|
||||
})
|
||||
.fold(quote_expr!(cx, 0), |sum, expr| quote_expr!(cx, $sum + $expr));
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
let mut state = try!(_serializer.serialize_struct($type_name, $len));
|
||||
$serialize_fields
|
||||
_serializer.serialize_struct_end(state)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_item_enum(
|
||||
@ -283,7 +281,7 @@ fn serialize_item_enum(
|
||||
ty: P<ast::Ty>,
|
||||
variants: &[Variant],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let arms: Vec<_> =
|
||||
variants.iter()
|
||||
.enumerate()
|
||||
@ -301,11 +299,11 @@ fn serialize_item_enum(
|
||||
})
|
||||
.collect();
|
||||
|
||||
quote_expr!(cx,
|
||||
quote_block!(cx, {
|
||||
match *self {
|
||||
$arms
|
||||
}
|
||||
)
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_variant(
|
||||
@ -326,18 +324,17 @@ fn serialize_variant(
|
||||
match variant.style {
|
||||
Style::Unit => {
|
||||
quote_arm!(cx,
|
||||
$type_ident::$variant_ident => {
|
||||
$type_ident::$variant_ident =>
|
||||
_serde::ser::Serializer::serialize_unit_variant(
|
||||
_serializer,
|
||||
$type_name,
|
||||
$variant_index,
|
||||
$variant_name,
|
||||
)
|
||||
}
|
||||
),
|
||||
)
|
||||
},
|
||||
Style::Newtype => {
|
||||
let expr = serialize_newtype_variant(
|
||||
let block = serialize_newtype_variant(
|
||||
cx,
|
||||
builder,
|
||||
type_name,
|
||||
@ -349,7 +346,7 @@ fn serialize_variant(
|
||||
);
|
||||
|
||||
quote_arm!(cx,
|
||||
$type_ident::$variant_ident(ref __simple_value) => { $expr }
|
||||
$type_ident::$variant_ident(ref __simple_value) => $block
|
||||
)
|
||||
},
|
||||
Style::Tuple => {
|
||||
@ -365,7 +362,7 @@ fn serialize_variant(
|
||||
)
|
||||
.build();
|
||||
|
||||
let expr = serialize_tuple_variant(
|
||||
let block = serialize_tuple_variant(
|
||||
cx,
|
||||
builder,
|
||||
type_name,
|
||||
@ -377,7 +374,7 @@ fn serialize_variant(
|
||||
);
|
||||
|
||||
quote_arm!(cx,
|
||||
$pat => { $expr }
|
||||
$pat => $block
|
||||
)
|
||||
}
|
||||
Style::Struct => {
|
||||
@ -395,7 +392,7 @@ fn serialize_variant(
|
||||
}
|
||||
let pat = pat.build();
|
||||
|
||||
let expr = serialize_struct_variant(
|
||||
let block = serialize_struct_variant(
|
||||
cx,
|
||||
builder,
|
||||
variant_index,
|
||||
@ -407,7 +404,7 @@ fn serialize_variant(
|
||||
);
|
||||
|
||||
quote_arm!(cx,
|
||||
$pat => { $expr }
|
||||
$pat => $block
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -422,14 +419,14 @@ fn serialize_newtype_variant(
|
||||
item_ty: P<ast::Ty>,
|
||||
generics: &ast::Generics,
|
||||
field: &Field,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let mut field_expr = quote_expr!(cx, __simple_value);
|
||||
if let Some(path) = field.attrs.serialize_with() {
|
||||
field_expr = wrap_serialize_with(cx, builder,
|
||||
&item_ty, generics, &field.ty, path, field_expr);
|
||||
}
|
||||
|
||||
quote_expr!(cx,
|
||||
quote_block!(cx, {
|
||||
_serde::ser::Serializer::serialize_newtype_variant(
|
||||
_serializer,
|
||||
$type_name,
|
||||
@ -437,7 +434,7 @@ fn serialize_newtype_variant(
|
||||
$variant_name,
|
||||
$field_expr,
|
||||
)
|
||||
)
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_tuple_variant(
|
||||
@ -449,7 +446,7 @@ fn serialize_tuple_variant(
|
||||
generics: &ast::Generics,
|
||||
structure_ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
let serialize_stmts = serialize_tuple_struct_visitor(
|
||||
cx,
|
||||
builder,
|
||||
@ -462,11 +459,11 @@ fn serialize_tuple_variant(
|
||||
|
||||
let len = serialize_stmts.len();
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
let mut state = try!(_serializer.serialize_tuple_variant($type_name, $variant_index, $variant_name, $len));
|
||||
$serialize_stmts
|
||||
_serializer.serialize_tuple_variant_end(state)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_struct_variant(
|
||||
@ -478,7 +475,7 @@ fn serialize_struct_variant(
|
||||
ty: P<ast::Ty>,
|
||||
fields: &[Field],
|
||||
item_attrs: &attr::Item,
|
||||
) -> P<ast::Expr> {
|
||||
) -> P<ast::Block> {
|
||||
|
||||
let serialize_fields = serialize_struct_visitor(
|
||||
cx,
|
||||
@ -504,7 +501,7 @@ fn serialize_struct_variant(
|
||||
})
|
||||
.fold(quote_expr!(cx, 0), |sum, expr| quote_expr!(cx, $sum + $expr));
|
||||
|
||||
quote_expr!(cx, {
|
||||
quote_block!(cx, {
|
||||
let mut state = try!(_serializer.serialize_struct_variant(
|
||||
$item_name,
|
||||
$variant_index,
|
||||
@ -513,7 +510,7 @@ fn serialize_struct_variant(
|
||||
));
|
||||
$serialize_fields
|
||||
_serializer.serialize_struct_variant_end(state)
|
||||
})
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn serialize_tuple_struct_visitor(
|
||||
|
Loading…
x
Reference in New Issue
Block a user