Crate endian_trait_derive [−] [src]
Custom Derive for Endian Trait
This crate provides a custom-derive procedural macro for the Endian trait. This macro simply takes the component fields of the type on which it is annotated and attempts to call the Endian conversion on each field. This means that Endian can only be derived on types composed of types that are all themselves Endian. Attempting to derive Endian on a type with a non-Endian type in it will result in a compilation error.
Use Case
Network serialization of complex types. That's pretty much it. This trait does
not require explicitly, but in practice basically does need, that the types on
which it is implemented are repr(C)
or repr(packed)
. You can get away with
using it on types that do not have that representation if you can guarantee that
you know how to properly handle the actual byte representation and the generator
and consumer are the same Rust version.
Usage
Import the crate and its macros. You can't make use of this crate without the
endian_trait
crate, and that's where fuller documentation can be found. You
can then add a #[derive(Endian)]
marker on structs (regular, tuple, or void).
Enums are not yet supported. All elements of the struct must themselves be
Endian.
extern crate endian_trait; #[macro_use] extern crate endian_trait_derive; #[derive(Endian)] struct Foo<A: Endian, B: Endian> { bar: A, baz: B, }
Functions
endian_trait |
Hook for receiving |