#offset #derive #mem #offset-of

macro no-std repr_offset_derive

For deriving the offsets of fields for types with a stable layout

4 releases (2 breaking)

0.2.0 Jan 29, 2021
0.1.1 Jul 30, 2020
0.1.0 Jun 14, 2020
0.0.0 May 21, 2020

#7 in #offset-of

Download history 12/week @ 2024-05-16 18/week @ 2024-05-23 34/week @ 2024-05-30 33/week @ 2024-06-06 28/week @ 2024-06-13 25/week @ 2024-06-20 16/week @ 2024-06-27 19/week @ 2024-07-04 27/week @ 2024-07-11 29/week @ 2024-07-18 34/week @ 2024-07-25 29/week @ 2024-08-01 22/week @ 2024-08-08 22/week @ 2024-08-15 22/week @ 2024-08-22 16/week @ 2024-08-29

87 downloads per month
Used in repr_offset

Zlib license

16KB
348 lines

Rust crates-io api-docs

repr_offset allows computing and safely using field offsets from types with a defined layout.

Currently only #[repr(C)]/#[repr(C,packed)]/#[repr(C,align)] structs are supported.

Features

These are some of the features this library provides:

  • The ReprOffset derive macro, which outputs associated constants with the offsets of fields, and implements the GetFieldOffset trait for each field.

  • The FieldOffset type (how offsets are represented), with methods for operating on a field through a pointer to the struct, including getting a reference(or pointer) to the field.

  • The unsafe_struct_field_offsets macro as an alternative to the ReprOffset derive macro, most useful when the "derive" feature is disabled.

  • The GetFieldOffset trait, for getting the FieldOffset for a field, and the OFF!, off, PUB_OFF!, and pub_off macros for getting the FieldOffset for a field with a convenient syntax.

  • The extension traits from the ext module, which define methods for operating on a field, given a FieldOffset.

Examples

For examples you can look at the examples section of the documentation for the root module of the repr_offset crate

Future plans

None for now.

Cargo features

These are the cargo features in repr_offset:

  • derive (disabled by default): Enables the ReprOffset derive macro. This requires the same Rust versions as syn, which is currently >= 1.56.0.

  • "for_examples" (disabled by default): Enables the for_examples module, with types used in documentation examples.

Adding the "derive" feature to the Cargo.toml file:

repr_offset = { version = "0.2", features = ["derive"] }

no-std support

This library is unconditionally #![no_std],and that is unlikely to change in the future.

Minimum Rust version

This crate support Rust back to 1.41.0.

License

Licensed under the Zlib license

Dependencies

~1.7–2.6MB
~56K SLoC