#[derive(ToBytes)]
{
// Attributes available to this derive:
#[packbytes]
}
Expand description
Derive the ToBytes trait for structs where each field implements it and fieldless enums.
Const generics in stable don’t allow implementing ToBytes for arrays [T; N] where
T: ToBytes. This macro circumvents that by deriving a different implementation for fields
whose types are arrays, allowing the trait to be derived even for structs with such fields.
§Endianness
By default, the FromBytes and ToBytes derive macros assume that the data is prefered to be stored
in the little endian order.
You can change this by setting the attribute #[packbytes(be)] for big endian or #[packbytes(ne)]
for the platform native endian.
§Fieldless enums
The trait is implemented for fieldless enums by converting the numerical value (of the type
set by the repr attribute on the enum) to bytes.