Commit Graph

406 Commits

Author SHA1 Message Date
Lokathor
0a995ff0fc changelog 2024-11-19 10:27:52 -07:00
Alphyr
1400815a33
Improve fill_zeroes' use of ptr::write_bytes (#284) 2024-11-19 08:01:37 -07:00
Alphyr
13f4ae0cdf
Add functions to allocate zeroed Arc and Rc (#283)
These require rustc 1.82
2024-11-12 12:42:04 -07:00
zachs18
af8d110201
More TransparentWrapper impls (core::cmp::Reverse and core::num::Saturating) (#269)
* impl<T> TransparentWrapper<T> for core::cmp::Reverse<T>

* impl<T> TransparentWrapper<T> for core::num::Saturating<T>, with a new feature for non-base-MSRV stdlib TransparentWrapper impls.

* Restrict TransparentWrapper<T> for Reverse<T> to cfg(feature = "transparentwrapper_extra").

* nightly_docs for transparent_wrapper_extra

---------

Co-authored-by: Lokathor <zefria@gmail.com>
2024-10-30 23:30:11 -06:00
Gnome!
79a15d0a3f
Remove incorrect spanned quote usage (#279) 2024-10-19 09:14:32 -06:00
Lokathor
7b98ff1cec chore: Release bytemuck version 1.19.0 2024-10-12 22:09:07 -06:00
Lokathor
422acc0b16 changelog. 2024-10-12 22:07:56 -06:00
Christofer Nolander
da9b1874d8
add track_caller feature (#276)
closes #68
2024-10-12 22:06:43 -06:00
Timothy Hoffman
1c09edf7b0
fix #274 (#275) 2024-10-09 22:18:57 -06:00
Lokathor
48952a0246 chore: Release bytemuck_derive version 1.8.0 2024-10-06 16:48:29 -06:00
Lokathor
2cd97193ab changelog 2024-10-06 16:48:10 -06:00
zachs18
a637e1d983
derive(Zeroable) on fieldful enums and repr(C) enums (#257)
* Add support for deriving Zeroable for fieldful enums if:

1. the enum is repr(Int), repr(C), or repr(C, Int),
2. the enum has a variant with discriminant 0,
3. and all fields of the variant with discriminant 0 are Zeroable.

* Allow using derive(Zeroable) with explicit bounds. Update documentation and doctests.

* doc update

* doc update

* remove unused

* Factor out get_zero_variant helper function.

* Use i128 to track disciminants instead of i64.

* Add doc-comment for `get_fields`

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>

* Update derive/src/traits.rs

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>

---------

Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2024-09-24 12:30:38 -06:00
Thom Chiovoloni
bb368799c3
Improve documentation of features. (#272)
* Improve documentation of nightly features

* Document undocumented features
2024-09-05 19:57:56 -06:00
Lokathor
860c391345 chore: Release bytemuck version 1.18.0 2024-09-05 19:53:43 -06:00
Thom Chiovoloni
4c535f9a77
Clean up Cargo.toml (#271) 2024-09-05 19:51:06 -06:00
Lokathor
374d184e24
Update changelog.md 2024-09-05 19:46:57 -06:00
Thom Chiovoloni
19065703a5
Add a convenience feature indicating you're on the latest stable version of Rust (#270) 2024-09-05 19:36:58 -06:00
Lokathor
2d2b397d66 update the changelog to be less dismissive because we don't need that negativity. 2024-08-27 18:01:38 -06:00
Lokathor
dc059fd187 chore: Release bytemuck version 1.17.1 2024-08-27 10:34:15 -06:00
Lokathor
4bd50082ae changelog. 2024-08-27 10:33:57 -06:00
Lukasz Anforowicz
3f42bec539
Force #[repr(C)] layout to guarantee same offset of union fields. (#268)
https://rust-lang.github.io/unsafe-code-guidelines/layout/unions.html
points out that

    > [...] the default layout of Rust unions is, in general,
    > unspecified.
    >
    > That is, there are no general guarantees about the offset of the
    > fields, whether all fields have the same offset, what the call ABI
    > of the union is, etc.

This commit explicitly asks for `#[repr(C)]` layout to guarantee
that both fields have the same offeset.
2024-08-27 10:30:57 -06:00
Lokathor
3c42ba7f23 chore: Release bytemuck version 1.17.0 2024-08-16 00:43:55 -06:00
Lokathor
413aaafba9 changelog. 2024-08-16 00:43:43 -06:00
Lokathor
faff80450a chore: Release bytemuck_derive version 1.7.1 2024-08-16 00:40:22 -06:00
Lokathor
7be8c67b2a derive changelog 2024-08-16 00:39:48 -06:00
zachs18
bb62be5baa
Remove "dangling" terminology for zero-sized pointees. (#262)
* Update safety comment on BoxBytes pointer field.

* Update mentions of "dangling" pointers elsewhere in src/allocation.rs.
2024-08-11 01:59:50 -06:00
zachs18
5eecd33318
Make must_cast by-value and by-shared-ref functions const (#261)
* 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.
2024-08-11 01:59:06 -06:00
Richard Pringle
243302d3ef
Add bytemuck attribute to NoUninit derive (#259) 2024-08-02 08:09:49 -06:00
zachs18
e1baf85f09
Fix box_bytes_zst test (#260) 2024-07-30 21:59:13 -06:00
Lokathor
20f4a09404 chore: Release bytemuck version 1.16.3 2024-07-30 17:08:09 -06:00
Lokathor
9f7161ccf0 describe pr 256 2024-07-30 17:07:44 -06:00
zachs18
291a924518
Allow casting between slices of ZSTs and slices of non-ZSTs in all cases. (#256)
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].
2024-07-30 17:05:11 -06:00
Lokathor
758774d451 chore: Release bytemuck version 1.16.2 2024-07-30 16:37:41 -06:00
Lokathor
73cd363f72 changelog 2024-07-30 16:37:05 -06:00
zachs18
1c75146bb6
Fix UB when dropping BoxBytes owning a zero-sized layout (#258) 2024-07-30 16:23:38 -06:00
zachs18
005ee3254f
Fix panics in try_cast_slice_box etc (#254)
* 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.
2024-07-21 10:24:43 -06:00
Lokathor
02ffd53a4e chore: Release bytemuck version 1.16.1 2024-06-18 21:26:50 -06:00
Lokathor
e0364d28c8 update changelog 2024-06-18 21:26:34 -06:00
Trevor Gross
9b81537c5f
Support Zeroable and Pod for f16 and f128 (#251)
These are gated under a new feature flag `nightly_float`.

Fixes: <https://github.com/Lokathor/bytemuck/issues/250>
2024-06-18 21:24:29 -06:00
Lokathor
d15b8e0e6d
stupid branch stuff. (#248)
* 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

* derive changelog.

* chore: Release bytemuck_derive version 1.7.0
2024-05-28 12:30:53 -06:00
Lokathor
c9540064f3
Fix the errors CI is showing (#247)
* 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
2024-05-28 12:22:59 -06:00
Tom Dohrmann
a630404e18
support deriving Zeroable for fieldless enums (#233)
* support deriving Zeroable for fieldless enums

* add test for deriving Zeroable on enum
2024-05-28 11:53:32 -06:00
zachs18
9a27279008
Allow generics in derive(ByteEq, ByteHash). (#219)
Note that the ergonomics are still not great, since `NoUninit` is also required to use `derive(ByteEq, ByteHash)`, and `derive(NoUninit)` doesn't support generics,
but that *explicitly* doesn't support generics, instead of silently ignoring generics like `derive(ByteEq, ByteHash)` used to, so this is strictly an improvement.
2024-05-28 11:52:54 -06:00
Andrew Gazelka
1c3751410f
fix clippy lints (#137) 2024-05-28 11:31:06 -06:00
Urgau
f9f7bb10b3
Address unexpected_cfgs warnings instead of allowing the lint (#243) 2024-05-24 13:21:58 -06:00
Lokathor
89885d160a chore: Release bytemuck_derive version 1.6.1 2024-05-24 11:54:29 -06:00
Jay White
7094cb8b8e
Ignore clippy::multiple_bound_locations lint. (#242) 2024-05-24 11:52:56 -06:00
Lokathor
4c46b919e2 chore: Release bytemuck version 1.16.0 2024-05-13 11:08:36 -06:00
Lokathor
5287f8cf6d we can put out 1.16 without waiting for more 2024-05-13 11:08:13 -06:00
Lokathor
a41510f303 put const_zeroed into the changelog 2024-05-13 10:59:46 -06:00