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 2/week @ 2023-11-27 1/week @ 2023-12-11 5/week @ 2023-12-18 7/week @ 2024-02-12 52/week @ 2024-02-19 47/week @ 2024-02-26 25/week @ 2024-03-04 33/week @ 2024-03-11

158 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
~34K SLoC