bytevec::bytevec_impls!
[−]
[src]
macro_rules! bytevec_impls { {$(impl $name:ident {$($field:ident : $t:ty),*})*} => { ... }; }
Implements the byte serialization traits for the given structures.
This macro implements both the ByteEncodable
and ByteDecodable
traits
for the given struct
definitions. This macro does not declare the struct
definitions, the user should either declare them separately or use the
bytevec_decl
trait.
This trait also allows the user to create a partial implementation of the
serialization operations for a select number of the fields of the
structure. If the actual definition of the struct
has more fields than
the one provided to the macro, only the listed fields in the macro invocation
will be serialized and deserialized. In the deserialization process, the
rest of the fields of the struct
will be initialized using the value
returned from the Default::default()
method, so the struct
must
implement Default
.
Examples
#[derive(PartialEq, Eq, Debug, Default)] struct Vertex3d { x: u32, y: u32, z: u32 } bytevec_impls! { impl Vertex3d { x: u32, y: u32 } } fn main() { let p1 = Vertex3d {x: 32, y: 436, z: 0}; let bytes = p1.encode::<u32>().unwrap(); let p2 = Vertex3d::decode::<u32>(&bytes).unwrap(); assert_eq!(p1, p2); }