bytevec::bytevec_decl! [] [src]

macro_rules! bytevec_decl {
    {$($(#[$attr:meta])* struct $name:ident {$($field:ident : $t:ty),*})*} => { ... };
    {$($(#[$attr:meta])* pub struct $name:ident {$(pub $field:ident : $t:ty),*})*} => { ... };
    {$($(#[$attr:meta])* pub struct $name:ident {$($field:ident : $t:ty),*})*} => { ... };
}

Declares the given structures and implements the byte serialization traits.

This macro allows the user to declare an arbitrary number of structures that automatically implement both the ByteEncodable and ByteDecodable traits, as long as all of the fields also implement both traits.

Examples

bytevec_decl! {
    #[derive(PartialEq, Eq, Debug)]
    pub struct Point {
        x: u32,
        y: u32
    }
}

fn main() {
    let p1 = Point {x: 32, y: 436};
    let bytes = p1.encode::<u32>().unwrap();
    let p2 = Point::decode::<u32>(&bytes).unwrap();
    assert_eq!(p1, p2);
}