4 releases

0.2.2 Aug 5, 2020
0.2.1 Sep 24, 2019
0.2.0 Sep 23, 2019
0.1.1 Apr 20, 2019
0.1.0 Aug 2, 2018

#16 in #buffering

Download history 40/week @ 2024-07-19 49/week @ 2024-07-26 50/week @ 2024-08-02 45/week @ 2024-08-09 42/week @ 2024-08-16 43/week @ 2024-08-23 57/week @ 2024-08-30 52/week @ 2024-09-06 45/week @ 2024-09-13 60/week @ 2024-09-20 70/week @ 2024-09-27 54/week @ 2024-10-04 66/week @ 2024-10-11 48/week @ 2024-10-18 35/week @ 2024-10-25 42/week @ 2024-11-01

197 downloads per month
Used in 2 crates (via buffering)

BSD-3-Clause

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 the MyUnionType::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
~37K SLoC