Crate endian_trait_derive[][src]

Custom Derive for the 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

This crate shouldn't be used directly; use

#[macro_use]
extern crate endian_trait;

and this crate will be pulled in transitively.

By itself, this crate provides a custom-derive macro to emit a trait impl block that is syntactically valid but will fail to compile without the endian_trait crate and Endian trait in scope.

#[macro_use]
extern crate endian_trait;

use endian_trait::Endian;

#[derive(Endian)]
struct Foo<A: Endian, B: Endian> {
    bar: A,
    baz: B,
}

Functions

endian_trait

Hook for receiving #[derive(Endian)] code