From e3c20e1c64835e0da49f8db8cee72bc61c3d0b9e Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Wed, 20 Apr 2016 19:10:41 +0300 Subject: [PATCH] fix for raw struct --- ipc/codegen/src/serialization.rs | 15 ++++++--------- ipc/tests/binary.rs.in | 7 +++++++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/ipc/codegen/src/serialization.rs b/ipc/codegen/src/serialization.rs index 596f54d1a..adcaaf2bf 100644 --- a/ipc/codegen/src/serialization.rs +++ b/ipc/codegen/src/serialization.rs @@ -167,7 +167,10 @@ fn binary_expr_struct( ) -> Result { let size_exprs: Vec> = fields.iter().enumerate().map(|(index, field)| { let index_ident = builder.id(format!("__field{}", index)); - value_ident.and_then(|x| Some(quote_expr!(cx, $x . $index_ident .size()))) + value_ident.and_then(|x| { + let field_id = builder.id(field.ident.unwrap()); + Some(quote_expr!(cx, $x . $field_id .size())) + }) .unwrap_or_else(|| quote_expr!(cx, $index_ident .size())) }).collect(); @@ -184,9 +187,9 @@ fn binary_expr_struct( write_stmts.push(quote_stmt!(cx, let next_line = offset + $size_expr; ).unwrap()); match value_ident { Some(x) => { - let index_ident = builder.id(format!("{}", index)); + let field_id = builder.id(field.ident.unwrap()); write_stmts.push( - quote_stmt!(cx, $x . $index_ident .to_bytes(&mut buffer[offset..next_line]);).unwrap()) + quote_stmt!(cx, $x . $field_id .to_bytes(&mut buffer[offset..next_line]);).unwrap()) }, None => { let index_ident = builder.id(format!("__field{}", index)); @@ -370,11 +373,5 @@ fn binary_expr_variant( read: quote_arm!(cx, $pat => { $read_expr } ), }) }, -// _ => { -// cx.span_bug(span, -// &format!("#[derive(Binary)] Unsupported enum variant content, expected tuple/struct, found: {:?}", -// variant)); -// Err(Error) -// }, } } diff --git a/ipc/tests/binary.rs.in b/ipc/tests/binary.rs.in index 875220535..a4f2b7538 100644 --- a/ipc/tests/binary.rs.in +++ b/ipc/tests/binary.rs.in @@ -25,3 +25,10 @@ enum Root { number2: u64, }, } + +#[derive(Binary)] +struct DoubleRoot { + x1: u32, + x2: u64, + x3: u32, +}