abomonation::abomonate!
[−]
[src]
macro_rules! abomonate { ($t:ty) => { ... }; ($t:ty : $($field:ident),*) => { ... }; }
The abomonate!
macro takes a type name with an optional list of fields, and implements
'Abomonation' for the type, following the pattern of the tuple implementations: each method
calls the equivalent method on each of its fields.
Examples
#[macro_use] extern crate abomonation; use abomonation::{encode, decode, Abomonation}; #[derive(Eq, PartialEq)] struct MyStruct { a: String, b: u64, c: Vec<u8>, } abomonate!(MyStruct : a, b, c); fn main() { // create some test data out of recently-abomonable types let my_struct = MyStruct { a: "grawwwwrr".to_owned(), b: 0, c: vec![1,2,3] }; // encode a &MyStruct into a Vec<u8> let mut bytes = Vec::new(); encode(&my_struct, &mut bytes); // decode a &MyStruct from &mut [u8] binary data if let Ok((result, remaining)) = decode::<MyStruct>(&mut bytes) { assert!(result == &my_struct); assert!(remaining.len() == 0); } }