bytemuck/derive
Tom Dohrmann d10fbfc6ff
allow deriving CheckedBitPattern for enums with fields (#171)
* simplify `ToTokens` impl for `Representation`

Instead of collecting the representation and modifier into `Option`s
and determining whether a comma is needed manually, we can use the
`Puncutuated` struct which handles commas automatically.

This will also make emitting the `align` modifier in the future easier.

* emit alignment modifier

This is required for correctly implementing `CheckedBitPattern` because
we need the layout of the type and its `Bits` type to have the same
layout.

* add unit test for `#[repr]` parsing

* allow multiple alignment modifiers

According to RFC #1358, if multiple alignment modifiers are specified,
the resulting alignment is the maximum of all alignment modifiers.

* actually return the error we just created

* factor out the integer Repr's into their own type

This is a preparation step for adding support for `#[repr(C, int)]`.

* allow parsing `#[repr(C, int)]`

This can be used on enums with fields.

* derive `CheckedBitPattern` for enums with fields

The implementation mostly mirrors the desugaring described at
https://doc.rust-lang.org/reference/type-layout.html

* add comments and rename some idents

* update error message

* update docs for `CheckedBitPattern` derive

* add new nested test case, change generated type naming scheme

* fix wrong comment

* small nit

---------

Co-authored-by: Gray Olson <gray@grayolson.com>
2023-09-06 17:37:07 +02:00
..
src allow deriving CheckedBitPattern for enums with fields (#171) 2023-09-06 17:37:07 +02:00
tests allow deriving CheckedBitPattern for enums with fields (#171) 2023-09-06 17:37:07 +02:00
Cargo.toml chore: Release bytemuck_derive version 1.5.0 2023-09-05 15:15:09 -06:00
changelog.md docs. 2023-09-05 15:06:36 -06:00
LICENSE-APACHE Replace LICENCES-* symlinks with a licence copy. (#118) 2022-07-13 06:53:17 -06:00
LICENSE-MIT Replace LICENCES-* symlinks with a licence copy. (#118) 2022-07-13 06:53:17 -06:00
LICENSE-ZLIB Replace LICENCES-* symlinks with a licence copy. (#118) 2022-07-13 06:53:17 -06:00
README.md docs. 2023-09-05 15:06:36 -06:00

bytemuck_derive

Derive macros for bytemuck traits.

MSRV: None!

This is an opt-in bonus feature for bytemuck that doesn't particularly do anything you couldn't do yourself, and so MSRV is not a strong consideration for this crate.