Commit Graph

379 Commits

Author SHA1 Message Date
zachs18
911f43db98
Make checked::pod_read_unaligned require T: CheckedBitPattern (#150)
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.
2022-11-28 15:12:32 -07:00
yvt
f14410f329
Implement Zeroable on {Cell,Reverse}<impl Zeroable> (#149)
* Implement `Zeroable` on `Cell<impl Zeroable>`

* Implement `Zeroable` on `Reverse<impl Zeroable>`
2022-11-20 21:28:55 -07:00
yvt
0da8f3a28f
Implement Zeroable on UnsafeCell<impl Zeroable> (#148) 2022-11-20 16:40:41 -07:00
zachs18
c9e1ae1373
Remove where clause from derived TransparentWrapper impls. (#146)
* Remove where clause from derived TransparentWrapper impls.

* Add test for TransparentWrapper trait bound regression.
2022-11-20 16:40:20 -07:00
Christopher Serr
7311e9b4b8
Implement ByteEq and ByteHash derives (#144)
* 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
2022-11-17 13:13:24 -07:00
Lokathor
6b1b7cecd3
Update README.md 2022-11-07 09:17:28 -07:00
Lokathor
06a62314a3 (cargo-release) version 1.12.3 2022-11-05 15:53:28 -06:00
Lokathor
46e816c710 changelog. 2022-11-05 15:53:11 -06:00
Lokathor
5c9d81ca1a (cargo-release) version 1.3.0 2022-11-05 15:49:51 -06:00
Lokathor
86226cefc4 changelog. 2022-11-05 15:48:37 -06:00
Christopher Serr
02021fba24
Conditionally compile in Arc (#140)
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.
2022-11-05 07:00:40 -06:00
John Nunley
518baf9c0b
Allow repr(transparent) to be used generically in derive(Pod) (#139)
* Enabled transparent generics

* Move trait checks to implementation block

* Replace add_trait_marker impl
2022-11-03 07:53:01 -06:00
Lokathor
7b67524a43 (cargo-release) version 1.12.2 2022-10-30 16:23:59 -06:00
Lokathor
579950fdb5 changelog 2022-10-30 16:23:27 -06:00
Lokathor
12f5bfd62e clippy you are often a pain in my butt 2022-10-30 16:18:16 -06:00
Dennis Duda
f1571512d2
fix try_pod_read_unaligned... never having worked correctly (#138)
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.
2022-10-30 16:06:55 -06:00
zachs18
09dd2ffd68
Add cast_{arc,rc} (and slice and try), and {wrap,peel}_{arc,rc}. (#132)
* 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`.
2022-09-01 17:23:28 -06:00
Lokathor
950a3ed3b9 use the new derive updates. 2022-08-16 21:03:48 -06:00
Lokathor
3f2e91d3a6 (cargo-release) version 1.2.1 2022-08-16 21:01:26 -06:00
Lokathor
b7b438026d derive changlog. 2022-08-16 21:00:48 -06:00
Daniel Henry-Mantilla
d47d527ac2
Fix regression #127: support align in reprs again (#128) 2022-08-16 12:42:07 -06:00
Lokathor
995205de23 version bump 2022-08-14 10:10:45 -06:00
Lokathor
fd6b212a35 Update the readme to reflect the project status as of 2022-august 2022-08-14 09:52:26 -06:00
Lokathor
9ea5f65e0f add a note about intended MSRV of the derives (none!) 2022-08-14 09:50:39 -06:00
Lokathor
f053800ce0 bump bytemuck_derive version with changelog 2022-08-14 09:49:53 -06:00
Daniel Henry-Mantilla
1ebf7c251d
Cleanup: use a macro for reprs, use syn errors & fix cfg-target-arch (#124) 2022-08-12 06:50:51 -06:00
pali
bbd6a927ad
fix something_went_wrong on spirv (#125)
Removed Display trait bound on the SPIR-V architecture.
2022-08-11 12:11:48 -06:00
Tom Dohrmann
2c97676bfc
support deriving Pod for packed generic types. (#123)
* improve `#[repr]` parsing

* allow deriving `Pod` for packed generic types

* Revert "Update Cargo.toml"

This reverts commit 6632bcef2c.
2022-08-07 14:32:00 -06:00
Waffle Maybe
331762b014
run cargo fmt (#120) 2022-07-24 09:27:49 -06:00
Lokathor
d75942c484 (cargo-release) version 1.11.0 2022-07-23 21:15:23 -06:00
Lokathor
5ed7a7fc52
Update changelog.md 2022-07-23 21:12:15 -06:00
Waffle Maybe
0fe2b2c568
Add {wrap,peel}_box functions to TransparentWrapperAlloc (#119)
* Add `{wrap,peel}_box` functions to `TransparentWrapperAlloc`

* Add tests for `{wrap,peel}_box`
2022-07-23 21:09:32 -06:00
Lokathor
a053f1d887 derive version bump. 2022-07-18 19:27:55 -06:00
Lokathor
89bbdb1620 spelling 2022-07-18 19:25:57 -06:00
Edward
2864b52591
Fix/syn broken semver (#116)
* fix(derive): syn backwards compatibility

* fix: bump minimum syn version more after tests
2022-07-18 19:25:00 -06:00
piwicode
9d90497f7c
Replace LICENCES-* symlinks with a licence copy. (#118)
Fixes the licences content in bytemuck_derive.

Archives on crates.io does not contain a licence copy, but
just a file containing the symlink relative path instead.

https://static.crates.io/crates/bytemuck_derive/bytemuck_derive-1.1.0.crate
2022-07-13 06:53:17 -06:00
daxpedda
237d7d3730
Avoid clippy::missing_const_for_fn (#115) 2022-07-08 17:16:25 -06:00
Gray Olson
e612031c1f
Add try_zeroed_vec and zeroed_vec (#117)
* 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 :)
2022-07-07 08:54:34 -06:00
Lokathor
bf68430b59 (cargo-release) version 1.10.0 2022-07-02 18:14:46 -06:00
Lokathor
919c69cc4e changelog 2022-07-02 15:46:07 -06:00
Lokathor
6beb5382ec move this little guy where he goes 2022-07-02 15:30:08 -06:00
Lokathor
fda9e9f852 improve docs 2022-07-02 15:29:48 -06:00
Lokathor
1f265a9e0d Move the FooInOption traits into their own files for easier organization. 2022-07-02 15:21:11 -06:00
Edward
abe55e525e
feat: add TransparentWrapperAlloc trait (#111)
* feat: add TransparentWrapperAlloc trait

* implements wrap_vec and peel_vec

* fix: review comments

* remote asserts as they don't do anything
* avoid issue with stacked borrows
2022-06-28 17:55:31 -06:00
Edward
e8cd71df54
feat: ZeroableInOption and PodInOption traits (#114)
* 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
2022-06-28 17:54:56 -06:00
nils
e9eb13e0e7
Use `-Zmiri-tag-raw-pointers in CI (#113)
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.
2022-06-26 10:22:38 -06:00
John
d691aa6a14
implement NoUninit for NonZero* (#107) 2022-06-06 13:20:34 -06:00
HeroicKatora
21e2ac55d7
Note on shared references to Pod-like types (#106)
* Note on shared references to Pod-like types

* Expand explanation of no-interior-mutability
2022-05-19 11:47:54 -06:00
Nicholas Bishop
96f2e549b3
Fix docstring typo (#104) 2022-05-13 14:51:43 -06:00
mystise
d8b67687f3
Add cast_slice_box and try_cast_slice_box, changed try_cast_vec to adjust length and capacity when valid. (#100)
* 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
2022-04-19 11:50:28 -06:00