commas
This commit is contained in:
parent
4670fd43ed
commit
2947a91c3e
@ -43,7 +43,7 @@ pub fn expand_serialization_implementation(
|
|||||||
_ => {
|
_ => {
|
||||||
cx.span_err(meta_item.span, "`#[derive(Binary)]` may only be applied to structs and enums");
|
cx.span_err(meta_item.span, "`#[derive(Binary)]` may only be applied to structs and enums");
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let builder = aster::AstBuilder::new().span(span);
|
let builder = aster::AstBuilder::new().span(span);
|
||||||
@ -53,7 +53,7 @@ pub fn expand_serialization_implementation(
|
|||||||
Err(Error) => {
|
Err(Error) => {
|
||||||
// An error occured, but it should have been reported already.
|
// An error occured, but it should have been reported already.
|
||||||
return;
|
return;
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
push(Annotatable::Item(impl_item))
|
push(Annotatable::Item(impl_item))
|
||||||
@ -72,7 +72,7 @@ fn serialize_item(
|
|||||||
item.span,
|
item.span,
|
||||||
"`#[derive(Binary)]` may only be applied to structs and enums");
|
"`#[derive(Binary)]` may only be applied to structs and enums");
|
||||||
return Err(Error);
|
return Err(Error);
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let ty = builder.ty().path()
|
let ty = builder.ty().path()
|
||||||
@ -145,7 +145,7 @@ fn binary_expr(
|
|||||||
cx.span_bug(item.span,
|
cx.span_bug(item.span,
|
||||||
"expected ItemStruct or ItemEnum in #[derive(Binary)]");
|
"expected ItemStruct or ItemEnum in #[derive(Binary)]");
|
||||||
Err(Error)
|
Err(Error)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,12 +174,12 @@ fn binary_expr_struct(
|
|||||||
Some(quote_expr!(cx,
|
Some(quote_expr!(cx,
|
||||||
match $field_type_ident::len_params() {
|
match $field_type_ident::len_params() {
|
||||||
0 => mem::size_of::<$field_type_ident>(),
|
0 => mem::size_of::<$field_type_ident>(),
|
||||||
_ => $x. $field_id .size()
|
_ => $x. $field_id .size(),
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| quote_expr!(cx, match $field_type_ident::len_params() {
|
.unwrap_or_else(|| quote_expr!(cx, match $field_type_ident::len_params() {
|
||||||
0 => mem::size_of::<$field_type_ident>(),
|
0 => mem::size_of::<$field_type_ident>(),
|
||||||
_ => $index_ident .size()
|
_ => $index_ident .size(),
|
||||||
}))
|
}))
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
@ -210,12 +210,12 @@ fn binary_expr_struct(
|
|||||||
None => {
|
None => {
|
||||||
let index_ident = builder.id(format!("__field{}", index));
|
let index_ident = builder.id(format!("__field{}", index));
|
||||||
quote_expr!(cx, $index_ident)
|
quote_expr!(cx, $index_ident)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
write_stmts.push(quote_stmt!(cx, let next_line = offset + match $field_type_ident::len_params() {
|
write_stmts.push(quote_stmt!(cx, let next_line = offset + match $field_type_ident::len_params() {
|
||||||
0 => mem::size_of::<$field_type_ident>(),
|
0 => mem::size_of::<$field_type_ident>(),
|
||||||
_ => { let size = $member_expr .size(); length_stack.push_back(size); size }
|
_ => { let size = $member_expr .size(); length_stack.push_back(size); size },
|
||||||
}).unwrap());
|
}).unwrap());
|
||||||
|
|
||||||
write_stmts.push(quote_stmt!(cx,
|
write_stmts.push(quote_stmt!(cx,
|
||||||
@ -227,7 +227,7 @@ fn binary_expr_struct(
|
|||||||
map_stmts.push(quote_stmt!(cx, map[$field_index] = total;).unwrap());
|
map_stmts.push(quote_stmt!(cx, map[$field_index] = total;).unwrap());
|
||||||
map_stmts.push(quote_stmt!(cx, let size = match $field_type_ident::len_params() {
|
map_stmts.push(quote_stmt!(cx, let size = match $field_type_ident::len_params() {
|
||||||
0 => mem::size_of::<$field_type_ident>(),
|
0 => mem::size_of::<$field_type_ident>(),
|
||||||
_ => length_stack.pop_front().unwrap()
|
_ => length_stack.pop_front().unwrap(),
|
||||||
}).unwrap());
|
}).unwrap());
|
||||||
map_stmts.push(quote_stmt!(cx, total = total + size;).unwrap());
|
map_stmts.push(quote_stmt!(cx, total = total + size;).unwrap());
|
||||||
};
|
};
|
||||||
@ -246,7 +246,7 @@ fn binary_expr_struct(
|
|||||||
let map_variant = P(fields_sequence(cx, &ty, fields, &instance_ident.unwrap_or(builder.id("Self"))));
|
let map_variant = P(fields_sequence(cx, &ty, fields, &instance_ident.unwrap_or(builder.id("Self"))));
|
||||||
quote_expr!(cx, { $map_stmts; Ok($map_variant) })
|
quote_expr!(cx, { $map_stmts; Ok($map_variant) })
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(BinaryExpressions {
|
Ok(BinaryExpressions {
|
||||||
@ -275,7 +275,7 @@ fn binary_expr_item_struct(
|
|||||||
Some(builder.id("self")),
|
Some(builder.id("self")),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
ast::VariantData::Struct(ref fields, _) => {
|
ast::VariantData::Struct(ref fields, _) => {
|
||||||
binary_expr_struct(
|
binary_expr_struct(
|
||||||
cx,
|
cx,
|
||||||
@ -544,7 +544,7 @@ fn binary_expr_variant(
|
|||||||
}),
|
}),
|
||||||
read: quote_arm!(cx, $variant_index_ident => { $read_expr } ),
|
read: quote_arm!(cx, $variant_index_ident => { $read_expr } ),
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
ast::VariantData::Struct(ref fields, _) => {
|
ast::VariantData::Struct(ref fields, _) => {
|
||||||
let field_names: Vec<_> = (0 .. fields.len())
|
let field_names: Vec<_> = (0 .. fields.len())
|
||||||
.map(|i| builder.id(format!("__field{}", i)))
|
.map(|i| builder.id(format!("__field{}", i)))
|
||||||
|
Loading…
Reference in New Issue
Block a user