Currently, `checked::pod_read_unaligned` requires `T: AnyBitPattern`. (This was likely just a copy-paste error from when the function was introduced in #91.)
There should be no current UB nor semver breakage, since this only relaxes the bound (any type this previously worked with was already sound and will continue to work).
`checked::try_pod_read_unaligned has the correct `T: CheckedBitPattern` bound.
* Implement `ByteEq` and `ByteHash` derives
This adds the derives `ByteEq` and `ByteHash` that can be used as an
alternative to the `Eq` / `PartialEq` and `Hash` derives from the
standard library. The difference is that these variants use `bytemuck`
to convert their values to byte slices before comparing / hashing them.
This allows the comparisons to turn into a simple `memcmp` / `bcmp` (or
completely inlined as a few vector instructions) and allows hashers to
process all bytes at once, possibly allowing for some vector operations
as well.
Here's a quick comparison of the generated assembly:
![https://i.imgur.com/CGTSWTZ.png](https://i.imgur.com/CGTSWTZ.png)
* Address review comments
Apparently the latest release of `bytemuck` doesn't compile on some of
the targets that it used to because it uses `Arc`. `Arc` is not a type
that exists on every target, because not every targets supports atomics.
It seems like a copy-paste error has happened between `try_from_bytes`/`try_from_bytes_mut` and `try_pod_read_unaligned`, causing `internal::try_pod_read_unaligned` to try to read a &T::Bits instead of a T::Bits, usually failing with a `SizeMismatch` error. In the worst case, this allows UB in safe code by having a type allowing any bit pattern and being pointer-sized.
* Add `allocation::{try_,}cast_{arc,rc}`, and add `{wrap,peel}_{arc,rc}` to `TransparentWrapperAlloc`.
* Avoid intermediate slice reference in `try_cast_slice_{arc,rc}`.
* remove `unsafe` block; run `cargo +nightly fmt` (ignoring files I didn't modify)
* Make `cast_rc` (etc) have the same bounds as `cast_mut`, due to the existence of `Rc::get_mut_unchecked`.
* add `try_zeroed_vec` and `zeroed_vec`, adjust impl of `try_zeroed_slice_box`
* go back to returning an error rather than calling handle_alloc_error
* use boxed slice .into_vec instead :)
* same as Zeroable and Pod but for types which are Zeroable and Pod when
wrapped in Option
* allows downstream users to implement Zeroable and Pod for their own
Option<T> types without running into orphan rules
Normal Miri does not provide sufficient safety guarantees. Using the flag `-Zmiri-tag-raw-pointers` also checks usage of pointers in a more strict way.
* Added try_cast_slice_box and cast_slice_box
* Modified try_cast_slice_box and try_cast_vec to recalculate the length if the change in size between the two types is valid.
* Ran cargo format