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

#17 in #buffering

Download history 49/week @ 2024-08-26 57/week @ 2024-09-02 51/week @ 2024-09-09 42/week @ 2024-09-16 62/week @ 2024-09-23 73/week @ 2024-09-30 51/week @ 2024-10-07 68/week @ 2024-10-14 40/week @ 2024-10-21 24/week @ 2024-10-28 43/week @ 2024-11-04 36/week @ 2024-11-11 57/week @ 2024-11-18 59/week @ 2024-11-25 43/week @ 2024-12-02 58/week @ 2024-12-09

223 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
~38K SLoC