* 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>