* Add support for deriving Zeroable for fieldful enums if:
1. the enum is repr(Int), repr(C), or repr(C, Int),
2. the enum has a variant with discriminant 0,
3. and all fields of the variant with discriminant 0 are Zeroable.
* Allow using derive(Zeroable) with explicit bounds. Update documentation and doctests.
* doc update
* doc update
* remove unused
* Factor out get_zero_variant helper function.
* Use i128 to track disciminants instead of i64.
* Add doc-comment for `get_fields`
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
* Update derive/src/traits.rs
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
---------
Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
https://rust-lang.github.io/unsafe-code-guidelines/layout/unions.html
points out that
> [...] the default layout of Rust unions is, in general,
> unspecified.
>
> That is, there are no general guarantees about the offset of the
> fields, whether all fields have the same offset, what the call ABI
> of the union is, etc.
This commit explicitly asks for `#[repr(C)]` layout to guarantee
that both fields have the same offeset.
* Make must_cast by-value and by-shared-ref functions const (but not by-mut-ref)
* Add comment for transmute! macro new arm, and update Cargo.toml comment for must_cast MSRV.
Casting ZST to non-ZST will result in a slice length of 0.
Casting non-ZST to ZST will only work if the input slice has length 0, and results in a slice length of 0; if the input slice is not of length 0, PodCastError::OutputSliceWouldHaveSlop is returned.
Updates the docs of the PodCastError variants to reflect when they can occur.
Updates the docs of try_cast_slice (and checked::) to remove note about ZST <-> non-ZST not being allowed.
Update bytes_of(_mut) to remove ZST check, since casting [ZST] -> [u8] is now allowed directly using cast_slice(_mut).
Update must_cast_slice checks and doctests to allow [ZST] -> [non-ZST], but disallow [non-ZST] -> [ZST].
* Fix panics in try_cast_slice_{box,rc,arc},cast_vec.
Casting from non-empty non-ZST slices to ZST slices now returns Err(SizeMismatch) (instead of panicking).
Casting from empty non-ZST slices to ZST slices is allowed and returns an empty slice (instead of panicking).
Casting from ZST slices to non-ZST slices is allowed and returns an empty slice (status quo).
* Add tests for cast_slice_box,rc,arc.
* Change #![allow(clippy::missing_docs_in_private_items)] to #[allow(clippy::missing_docs_in_private_items)], also rustfmt went wild
* fix for 1.34 building.
* clippy be quiet
* derive changelog.
* chore: Release bytemuck_derive version 1.7.0
* Change #![allow(clippy::missing_docs_in_private_items)] to #[allow(clippy::missing_docs_in_private_items)], also rustfmt went wild
* fix for 1.34 building.
* clippy be quiet
Note that the ergonomics are still not great, since `NoUninit` is also required to use `derive(ByteEq, ByteHash)`, and `derive(NoUninit)` doesn't support generics,
but that *explicitly* doesn't support generics, instead of silently ignoring generics like `derive(ByteEq, ByteHash)` used to, so this is strictly an improvement.