[−][src]Crate buffering_nocopy_macro
Structure
This crate provides the procedural macro NoCopy
to the buffering crate. Buffering is feature
flagged to be able to use only this macro so there is no reason for this to be used outside of
that crate.
Restrictions
This only works currently if the following conditions are met for the data type:
- It is a struct with named fields
- The type of each field is stack-allocatable and the size is known at compile time, or in other words, the size does not change
Provided methods
Each struct to which NoCopy
is applied will generate a union type to be used for buffer
operations. Traversal works like this:
- The union can be initialized either as a struct assigned to the
.structure()
field of the union or using theMyUnionType::new_buffer()
method and providing a slice - The union also provides methods
.get_your_field_name
and.set_your_field_name
that are generated per struct field (and whereyour_field_name
is replaced by the actual name of the field) - Each getter and setter will respect endianness set by the corresponding field attribute provided in the original struct
Recognized attributes
Attributes can be added to fields to specify whether they should be interpreted as big endian values
or little endian values in the form #[endian = "big"]
or #[endian = "little"]
. If neither
is specified, native endian is assumed. It is provided on a per-field basis due to restrictions
on what types provide the to_be
, etc. methods. These fields should be used when doing
internet networking to assure cross-architecture portability. Protocols that assume native
endian buffer representation do not need these attributes. A struct-level attribute is also
provided as #[name = "MyUnionNameHere"]
to override the autogenerated name for the resulting
union.
Derive Macros
NoCopy | Procedural macro that will derive getters and setters with appropriate endianness for every field defined in the struct |