Minor cleanup
This commit is contained in:
parent
5e98a83717
commit
11f47bd51f
@ -162,6 +162,9 @@ fn deserialize_substructure(
|
|||||||
enum_def,
|
enum_def,
|
||||||
&trait_generics,
|
&trait_generics,
|
||||||
&type_generics,
|
&type_generics,
|
||||||
|
visitor_item,
|
||||||
|
visitor_ty,
|
||||||
|
visitor_expr,
|
||||||
value_ty,
|
value_ty,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -218,17 +221,18 @@ fn deserialize_struct(
|
|||||||
value_ty: P<ast::Ty>,
|
value_ty: P<ast::Ty>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
match *fields {
|
match *fields {
|
||||||
Unnamed(ref fields) => {
|
Unnamed(ref fields) if fields.is_empty() => {
|
||||||
if fields.is_empty() {
|
deserialize_unit_struct(
|
||||||
deserialize_struct_empty_fields(
|
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
type_ident,
|
type_ident,
|
||||||
struct_ident,
|
struct_ident,
|
||||||
struct_path,
|
struct_path,
|
||||||
state)
|
state,
|
||||||
} else {
|
)
|
||||||
deserialize_struct_unnamed_fields(
|
}
|
||||||
|
Unnamed(ref fields) => {
|
||||||
|
deserialize_tuple_struct(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
struct_ident,
|
struct_ident,
|
||||||
@ -242,7 +246,6 @@ fn deserialize_struct(
|
|||||||
value_ty,
|
value_ty,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Named(ref fields) => {
|
Named(ref fields) => {
|
||||||
deserialize_struct_named_fields(
|
deserialize_struct_named_fields(
|
||||||
cx,
|
cx,
|
||||||
@ -263,7 +266,7 @@ fn deserialize_struct(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct_empty_fields(
|
fn deserialize_unit_struct(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
type_ident: Ident,
|
type_ident: Ident,
|
||||||
@ -312,7 +315,7 @@ fn deserialize_struct_empty_fields(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn deserialize_struct_unnamed_fields(
|
fn deserialize_tuple_struct(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
struct_ident: Ident,
|
struct_ident: Ident,
|
||||||
@ -331,7 +334,7 @@ fn deserialize_struct_unnamed_fields(
|
|||||||
.map(|i| builder.id(&format!("__field{}", i)))
|
.map(|i| builder.id(&format!("__field{}", i)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let visit_seq_expr = declare_visit_seq(
|
let visit_seq_expr = deserialize_seq(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
struct_path,
|
struct_path,
|
||||||
@ -369,7 +372,7 @@ fn deserialize_struct_unnamed_fields(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn declare_visit_seq(
|
fn deserialize_seq(
|
||||||
cx: &ExtCtxt,
|
cx: &ExtCtxt,
|
||||||
builder: &aster::AstBuilder,
|
builder: &aster::AstBuilder,
|
||||||
struct_path: ast::Path,
|
struct_path: ast::Path,
|
||||||
@ -664,15 +667,13 @@ fn deserialize_enum(
|
|||||||
enum_def: &EnumDef,
|
enum_def: &EnumDef,
|
||||||
trait_generics: &ast::Generics,
|
trait_generics: &ast::Generics,
|
||||||
type_generics: &ast::Generics,
|
type_generics: &ast::Generics,
|
||||||
|
visitor_item: P<ast::Item>,
|
||||||
|
visitor_ty: P<ast::Ty>,
|
||||||
|
visitor_expr: P<ast::Expr>,
|
||||||
value_ty: P<ast::Ty>,
|
value_ty: P<ast::Ty>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let where_clause = &trait_generics.where_clause;
|
let where_clause = &trait_generics.where_clause;
|
||||||
|
|
||||||
let (visitor_struct, visitor_expr) = deserialize_visitor(
|
|
||||||
builder,
|
|
||||||
trait_generics,
|
|
||||||
);
|
|
||||||
|
|
||||||
let type_name = builder.expr().str(type_ident);
|
let type_name = builder.expr().str(type_ident);
|
||||||
|
|
||||||
// Match arms to extract a variant from a string
|
// Match arms to extract a variant from a string
|
||||||
@ -688,9 +689,11 @@ fn deserialize_enum(
|
|||||||
fields,
|
fields,
|
||||||
cx.expr_ident(span, cx.ident_of("visitor")),
|
cx.expr_ident(span, cx.ident_of("visitor")),
|
||||||
variant,
|
variant,
|
||||||
|
visitor_item.clone(),
|
||||||
|
visitor_ty.clone(),
|
||||||
|
visitor_expr.clone(),
|
||||||
&value_ty,
|
&value_ty,
|
||||||
&trait_generics,
|
&trait_generics,
|
||||||
&type_generics,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let s = builder.expr().str(name);
|
let s = builder.expr().str(name);
|
||||||
@ -699,7 +702,7 @@ fn deserialize_enum(
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
$visitor_struct;
|
$visitor_item
|
||||||
|
|
||||||
impl $trait_generics ::serde::de::Visitor for __Visitor $type_generics $where_clause {
|
impl $trait_generics ::serde::de::Visitor for __Visitor $type_generics $where_clause {
|
||||||
type Value = $value_ty;
|
type Value = $value_ty;
|
||||||
@ -742,9 +745,11 @@ fn deserialize_enum_variant(
|
|||||||
fields: &StaticFields,
|
fields: &StaticFields,
|
||||||
state: P<ast::Expr>,
|
state: P<ast::Expr>,
|
||||||
variant: &P<ast::Variant>,
|
variant: &P<ast::Variant>,
|
||||||
|
visitor_item: P<ast::Item>,
|
||||||
|
visitor_ty: P<ast::Ty>,
|
||||||
|
visitor_expr: P<ast::Expr>,
|
||||||
value_ty: &P<ast::Ty>,
|
value_ty: &P<ast::Ty>,
|
||||||
trait_generics: &ast::Generics,
|
trait_generics: &ast::Generics,
|
||||||
type_generics: &ast::Generics,
|
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let variant_path = builder.path()
|
let variant_path = builder.path()
|
||||||
.ids(&[type_ident, variant_ident])
|
.ids(&[type_ident, variant_ident])
|
||||||
@ -765,8 +770,8 @@ fn deserialize_enum_variant(
|
|||||||
&*fields,
|
&*fields,
|
||||||
variant_path,
|
variant_path,
|
||||||
trait_generics,
|
trait_generics,
|
||||||
type_generics,
|
|
||||||
state,
|
state,
|
||||||
|
visitor_ty,
|
||||||
value_ty,
|
value_ty,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -778,8 +783,10 @@ fn deserialize_enum_variant(
|
|||||||
&*fields,
|
&*fields,
|
||||||
variant_path,
|
variant_path,
|
||||||
trait_generics,
|
trait_generics,
|
||||||
type_generics,
|
|
||||||
state,
|
state,
|
||||||
|
visitor_item,
|
||||||
|
visitor_ty,
|
||||||
|
visitor_expr,
|
||||||
value_ty,
|
value_ty,
|
||||||
variant,
|
variant,
|
||||||
)
|
)
|
||||||
@ -793,8 +800,8 @@ fn deserialize_enum_variant_seq(
|
|||||||
fields: &[Span],
|
fields: &[Span],
|
||||||
variant_path: ast::Path,
|
variant_path: ast::Path,
|
||||||
trait_generics: &ast::Generics,
|
trait_generics: &ast::Generics,
|
||||||
type_generics: &ast::Generics,
|
|
||||||
state: P<ast::Expr>,
|
state: P<ast::Expr>,
|
||||||
|
visitor_ty: P<ast::Ty>,
|
||||||
value_ty: &P<ast::Ty>,
|
value_ty: &P<ast::Ty>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
let where_clause = &trait_generics.where_clause;
|
let where_clause = &trait_generics.where_clause;
|
||||||
@ -804,22 +811,24 @@ fn deserialize_enum_variant_seq(
|
|||||||
.map(|i| token::str_to_ident(&format!("__field{}", i)))
|
.map(|i| token::str_to_ident(&format!("__field{}", i)))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let visit_seq_expr = declare_visit_seq(
|
let (visitor_item, visitor_expr) = deserialize_visitor(
|
||||||
|
builder,
|
||||||
|
trait_generics,
|
||||||
|
);
|
||||||
|
|
||||||
|
let visit_seq_expr = deserialize_seq(
|
||||||
cx,
|
cx,
|
||||||
builder,
|
builder,
|
||||||
variant_path,
|
variant_path,
|
||||||
&field_names,
|
&field_names,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (visitor_struct, visitor_expr) = deserialize_visitor(
|
|
||||||
builder,
|
|
||||||
trait_generics,
|
|
||||||
);
|
|
||||||
|
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
$visitor_struct
|
$visitor_item
|
||||||
|
|
||||||
impl $trait_generics ::serde::de::EnumSeqVisitor for __Visitor $type_generics $where_clause {
|
impl $trait_generics ::serde::de::EnumSeqVisitor
|
||||||
|
for $visitor_ty
|
||||||
|
$where_clause {
|
||||||
type Value = $value_ty;
|
type Value = $value_ty;
|
||||||
|
|
||||||
fn visit<
|
fn visit<
|
||||||
@ -840,8 +849,10 @@ fn deserialize_enum_variant_map(
|
|||||||
fields: &[(Ident, Span)],
|
fields: &[(Ident, Span)],
|
||||||
variant_path: ast::Path,
|
variant_path: ast::Path,
|
||||||
trait_generics: &ast::Generics,
|
trait_generics: &ast::Generics,
|
||||||
type_generics: &ast::Generics,
|
|
||||||
state: P<ast::Expr>,
|
state: P<ast::Expr>,
|
||||||
|
visitor_item: P<ast::Item>,
|
||||||
|
visitor_ty: P<ast::Ty>,
|
||||||
|
visitor_expr: P<ast::Expr>,
|
||||||
value_ty: &P<ast::Ty>,
|
value_ty: &P<ast::Ty>,
|
||||||
variant: &P<ast::Variant>,
|
variant: &P<ast::Variant>,
|
||||||
) -> P<ast::Expr> {
|
) -> P<ast::Expr> {
|
||||||
@ -876,16 +887,14 @@ fn deserialize_enum_variant_map(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let (visitor_struct, visitor_expr) = deserialize_visitor(
|
|
||||||
builder,
|
|
||||||
trait_generics
|
|
||||||
);
|
|
||||||
|
|
||||||
quote_expr!(cx, {
|
quote_expr!(cx, {
|
||||||
$visitor_struct
|
|
||||||
$field_devisitor
|
$field_devisitor
|
||||||
|
|
||||||
impl $trait_generics ::serde::de::EnumMapVisitor for __Visitor $type_generics $where_clause {
|
$visitor_item
|
||||||
|
|
||||||
|
impl $trait_generics ::serde::de::EnumMapVisitor
|
||||||
|
for $visitor_ty
|
||||||
|
$where_clause {
|
||||||
type Value = $value_ty;
|
type Value = $value_ty;
|
||||||
|
|
||||||
fn visit<
|
fn visit<
|
||||||
|
Loading…
x
Reference in New Issue
Block a user