* 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.
Uses the compiler to check that all non-wrapped fields are actually 1-ZSTs,
and uses Zeroable to check that all non-wrapped fields are "conjurable".
Additionally, relaxes the bound of `PhantomData<T: Zeroable>: Zeroable` to all `T: ?Sized`.
* Implement CheckedBitPattern for core::num::NonZero*.
* Add tests for CheckedBitPattern.
* Fix stacked borrows violation.
`<&mut T>::as_ptr` gives a `*const T` which is read-only. `<&mut T>::as_mut_ptr` is necessary to get a `*mut T`.
* MSRV fix.
* Add layout checks for CheckedBitPattern for NonZero*.
(Until Rust guarantees the layout of NonZero[int] matches [int].)
Also adds a test that will fail if any NonZero[int] has a different size or alignment than [int].
* 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.
* 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`.
* update rustfmt.toml
replace `merge_imports = true` (deprecated) with `imports_granularity = "Crate"`
* run `cargo +nightly fmt`
* rewrite docs and rename `Wrapped` to `Inner`
rewriting some docs for conciseness
rename `Wrapped` to `Inner`, because it's hard to visually differentiate between
`Wrapper` and `Wrapped`
* impl missing `TransparentWrapper::wrap_{}` fns
Implement 3 new wrapping functions on `TransparentWrapper` providing new
conversions.
- `TransparentWrapper::wrap(s: Inner) -> Self`
- `TransparentWrapper::wrap_slice(s: &[Inner]) -> &[Self]`
- `TransparentWrapper::wrap_slice_mut(s: &mut [Inner]) -> &mut [Self]`
* impl `TransparentWrapper::unwrap_{}` fns
Implement counterparts to `TransparentWrapper::wrap_{}` functions
providing reverse conversions.
- `TransparentWrapper::unwrap(self) -> Inner`
- `TransparentWrapper::unwrap_ref(&self) -> &Inner`
- `TransparentWrapper::unwrap_mut(&mut self) -> &mut Inner`
- `TransparentWrapper::unwrap_slice(s: &[Self]) -> &[Inner]`
- `TransparentWrapper::unwrap_slice_mut(s: &mut [Self]) -> &mut [Inner]`
* add `TransparentWrapper` UB test
This test is only for MIRI to check all trait functions on
`TransparentWrapper` if they cause any UB.
The output of the functions is not checked.
* small `TransparentWrapper` doc adjustments
* change fn signature on `TransparentWrapper`
Methods on `TransparentWrapper` trait are now associated functions.
They now take `Self` instead of `self` as argument)
- `TransparentWrapper::unwrap(s: Self)`
- `TransparentWrapper::unwrap_ref(s: &Self)`
- `TransparentWrapper::unwrap_mut(s: &mut Self)`
* Ensure functions that take generic <A, B> don't call them <T, U>
* Plug soundness hole in offset_of with safe_packed_borrows lint
* Add some more tests I noticed were missing (still many missing)
* Make CI way more thorough
* Fix running MSRV tests with unsupported `--feature`s
* Disable derive tests in sanitizers, and fix miri ci
* add basic derive macro for Pod and Zeroable for structs
* add derive macro for TransparentWrapper
* use core::mem::size_of instead of std::mem::size_of in generated code
* cleanup error handling a bit
* remove unneeded iter logic
* remove unneeded clone and order impl
* fix generics
* fix doc typo
Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
* remove unneeded lifetime anotation
* use unreachable for already rejected patch
Co-authored-by: Lucien Greathouse <me@lpghatguy.com>