* 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
* Explicitly document that pod_read_unaligned and try_pod_read_unaligned don't panic on unallowed reads
Their names make that reasonably clear already, but it doesn't hurt to
be explicit. Also, when choosing between `*from_bytes(x)` and
`pod_read_unaligned(x)`, it's good to have a clearly documented
criterion.
* Cosmetic doc changes
Add a couple of missing links, add a missing "like" (consistent with
other similar sentences).
* Remove redundant link
The redundant link emits a warning in `cargo doc`.
* Add functions for writing zeroed bytes to `&mut impl Zeroable` and `&mut [impl Zeroable]`
* Support `T: !Copy` in `fill_zero`/`write_zero`
* Zero bytes in the drop guard for write_zero
* Update src/lib.rs
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
---------
Co-authored-by: Lokathor <zefria@gmail.com>
Co-authored-by: Alphyr <47725341+a1phyr@users.noreply.github.com>
- new feature `nightly_docs` enables `doc_cfg` unstable feature that allows showing explicit dependencies on features.
- new cargo alias `nightly_docs` for a more convenient local documentation build `cargo +nightly nightly_docs --open`.
- annotate exported items and implementations depending on some feature with the corresponding `doc(cfg())` attribute.
- add the `nightly_docs` feature to the `[package.metadata.docs.rs]` section.
* cargo fmt src/must.rs
* Fix must.rs test failures.
* Under miri, use should_panic instead of compile_fail for must_cast doctests.
* Add description for workaround.
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`.
* `impl Zeroable for Atomic*`
fixes#74
* added feature flag for `zeroable_atomics`
Added documentation for some feature flags on the `Zeroable` trait.
Also fixed some invalid references in doc-comments.
* 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].
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.