4 releases
0.2.2 | Aug 5, 2020 |
---|---|
0.2.1 | Sep 24, 2019 |
0.2.0 |
|
0.1.1 | Apr 20, 2019 |
0.1.0 | Aug 2, 2018 |
#17 in #buffering
223 downloads per month
Used in 2 crates
(via buffering)
11KB
216 lines
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 allocated
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_field_name
and.set_field_name
that are generated per struct field - Getters and setters will respect endianness specified by the attribute
#[nocopy_macro(endian = "big")]
or#[nocopy_macro(endian = "little")]
provided in the original struct
Recognized attributes
Attributes can be added to the struct to specify whether integer types should be interpreted
as big endian values or little endian values in the form #[nocopy_macro(endian = "big")]
or #[nocopy_macro(endian = "little")]
. If neither is specified, native endian is assumed for
integers. Another available attribute is provided as #[nocopy_macro(name = "MyUnionNameHere")]
to override the default name for the autogenerated union.
Dependencies
~1.5MB
~38K SLoC