7 releases

0.2.2 Feb 25, 2023
0.2.1 Jan 30, 2021
0.1.2 Jan 8, 2021
0.1.1 Jul 30, 2020
0.0.1 May 21, 2020

#74 in No standard library

Download history 7480/week @ 2024-07-21 7181/week @ 2024-07-28 6475/week @ 2024-08-04 6487/week @ 2024-08-11 7822/week @ 2024-08-18 6101/week @ 2024-08-25 8205/week @ 2024-09-01 7263/week @ 2024-09-08 6442/week @ 2024-09-15 7234/week @ 2024-09-22 8734/week @ 2024-09-29 7165/week @ 2024-10-06 7244/week @ 2024-10-13 8458/week @ 2024-10-20 11608/week @ 2024-10-27 12409/week @ 2024-11-03

40,125 downloads per month
Used in 48 crates (via abi_stable)

Zlib license

210KB
2K SLoC

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

~74–385KB