macro_rules! union_formatter {
(#[target($buffer:ty)]
enum $name:ident : $key_type:ty {
$($key_value:expr; $case_name:ident($field_type:ty)),*
}) => { ... };
}Expand description
union_formatter define struct type and provide formatter.
object_formatter! {
#[target(Buffer<Cursor<Vec<u8>>>)]
AObject {
0; a: i32,
1; b: i64
}
}
object_formatter! {
#[target(Buffer<Cursor<Vec<u8>>>)]
OtherObject {
0; c: i32,
1; d: i64
}
}
union_formatter! {
#[target(Buffer<Cursor<Vec<u8>>>)]
enum UnionSample: i32 {
0; A(AObject),
1; Other(OtherObject)
}
}
let a: UnionSample = UnionSample::A(AObject { a: 1, b: 2 });
try!(writer.serialize(0, a));
let other: UnionSample = UnionSample::Other(OtherObject { c: 3, d: 4 });
try!(writer.serialize(0, other));