#offset-of #mem #offsetof #offset #no-std

no-std repr_offset

Offsets of fields for types with a stable layout

6 releases

0.2.1 Jan 30, 2021
0.2.0 Jan 29, 2021
0.1.2 Jan 8, 2021
0.1.1 Jul 30, 2020
0.0.1 May 21, 2020

#6 in #mem

Download history 517/week @ 2022-06-14 587/week @ 2022-06-21 835/week @ 2022-06-28 623/week @ 2022-07-05 306/week @ 2022-07-12 1143/week @ 2022-07-19 620/week @ 2022-07-26 313/week @ 2022-08-02 476/week @ 2022-08-09 314/week @ 2022-08-16 322/week @ 2022-08-23 437/week @ 2022-08-30 612/week @ 2022-09-06 496/week @ 2022-09-13 587/week @ 2022-09-20 429/week @ 2022-09-27

2,199 downloads per month
Used in 19 crates (via abi_stable)

Zlib license

205KB
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): Re-exports the ReprOffset derive macro from the repr_offset_derive crate.

  • "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

~245KB