-
Implement
Pod
andZeroable
forcore::arch::{x86, x86_64}::__m512
,__m512d
and__m512i
without nightly. Requires Rust 1.72, and is gated through theavx512_simd
cargo feature. -
Allow the use of
must_cast_mut
andmust_cast_slice_mut
in const contexts. Requires Rust 1.83, and is gated through themust_cast_extra
cargo feature. -
internal: introduced the
maybe_const_fn
macro that allows defining some function to be const depending upon somecfg
predicate.
- New functions to allocate zeroed
Arc
andRc
. Requires Rust 1.82 TransparentWrapper
impls forcore::cmp::Reverse
andcore::num::Saturating
.- internal: Simplified the library's
fill_zeroes
calls towrite_bytes
- Adds the
#[track_caller]
attribute to functions which may panic.
- Adds the
latest_stable_rust
cargo feature, which is a blanket feature that turns all other features on that are both sound and compatible with Stable rust.
- Adds
#[repr(C)]
to theunion Transmute<A, B>
type that's used internally for most of the transmutations.
- Makes the
must_cast
versions of the by-value and by-ref casts beconst
. The mut ref cast is unaffected for now (mut references aren't yet stable inconst fn
). This increases the MSRV of using that particular feature from 1.57 to 1.64.
- Fully described in #256, This makes casting slices to/from ZST elements more consistent between the crate's core module and other modules.
- Fixes potential UB where
BoxBytes
could attempt to free a dangling pointer if theLayout
is zero sized. This type was introduced in 1.14.1, so that version and the others up to and including 1.16.1 are now yanked for safety.
- NOT SEMVER SUPPORTED: Adds the
nightly_float
Cargo feature. This activates thef16
andf128
nightly features, and then providesZeroable
andPod
impls for those types.
- Adds a
const_zeroed
feature (MSRV 1.75) which puts azeroed
fn at the crate root. This is just like theZeroable::zeroed
method, but as aconst fn
.
This primarily relaxes the bounds on a From
impl.
Previously:
impl<T: NoUninit> From<Box<T>> for BoxBytes
Now:
impl<T: ?Sized + sealed::BoxBytesOf> From<Box<T>> for BoxBytes
All related functions and methods are similarly updated.
We believe this to be backwards compatible with all previous uses,
and now BoxBytes
can be converted to/from more types than before.
- The new std simd nightly features are apparently arch-specific. This adjusts the feature activation to be x86/ x86_64 only.
- Changes the name of the Nightly feature activated by the crate's
nightly_stdsimd
feature. This is needed as of (approximately) Nightly 2024-02-06 and later, because the Nightly feature was changed.
- docs clarifications.
write_zeroes
andfill_zeroes
functions: Writes (to one) or fills (a slice) zero bytes to all bytes covered by the provided reference. If your type has padding, this will even zero out the padding bytes.align_offset
feature: causes pointer alignment checks to use thealign_offset
pointer method rather than as-casting the pointer tousize
. This may improve codegen, if the compiler would have otherwise thought that the pointer address escaped. No formal benchmarks have been done either way.must_cast
feature: Addsmust_*
family of functions. These functions will fail to compile if the cast requested can't be statically known to succeed. The error messages can be kinda bad when this happens, but eliminating the possibility of a runtime error might be worth it to you.
- Remove the requirement for the source data type to be
AnyBitPattern
onpod_collect_to_vec
, allowing you to pod collect vecs ofchar
into vecs ofu32
, or whatever.
- Now depends on
bytemuck_derive-1.4.0
- Various small enhancements that would have been patch version updates, but which have been rolled into this minor version update.
- This has additional impls for existing traits and cleans up some internal code, but there's no new functions so I guess it counts as just a patch release.
- This bugfix makes the crate do stuff with
Arc
or not based on thetarget_has_atomic
config. Previously, some targets that have allocation but not atomics were getting errors. This raises the MSRV of theextern_crate_alloc
feature to 1.60, but opt-in features are not considered to be hard locked to 1.34 like the basic build of the crate is.
- Fixes
try_pod_read_unaligned
bug that made it always fail unless the target type was exactly pointer sized in which case UB could happen. TheCheckedBitPattern::is_valid_bit_pattern
was being asked to check that a reference to thepod
value was a valid bit pattern, rather than the actual bit pattern itself, and so the check could in some cases be illegally bypassed.
- Patch bumped the required
bytemuck_derive
version because of a regression in how it handledalign(N)
attributes.
- This minor version bump is caused by a version bump in our
bytemuck_derive
dependency, which is in turn caused by a mixup in the minimum version ofsyn
thatbytemuck_derive
uses. See Issue 122. There's not any specific "new" API as you might normally expect from a minor version bump. - pali fixed a problem with SPIR-V builds being
broken. The error handling functions were trying to be generic over
Display
, which the error types normally support, except on SPIR-V targets (which run on the GPU and don't have text formatting).
- WaffleLapkin added
wrap_box
andpeel_box
to theTransparentWrapperAlloc
trait. Default impls of these functions are provided, and (as usual with the transparent trait stuff) you should not override the default versions.
- TheEdward162 added the
ZeroableInOption
andPodInOption
traits. These are for types that areZeroable
orPod
when in an option, but not on their own. We provide impls for the various "NonZeroINTEGER" types incore
, and if you need to newtype a NonZero value then you can impl these traits when you userepr(transparent)
.
- Bumped the minimum
bytemuck_derive
dependency version from1.0
to1.1
. The fact thatbytemuck
andbytemuck_derive
are separate crates at all is an unfortunate technical limit of current Rust, woe and calamity.
- fu5ha added the
NoUninit
,AnyBitPattern
, andCheckedBitPattern
traits. This allows for a more fine-grained level of detail in what casting operations are allowed for a type. Types that already implementZeroable
andPod
will have a blanket impl for these new traits. This is a "preview" of the direction that the crate will probably go in the eventual 2.0 version. We're still waiting on Project Safe Transmute for an actual 2.0 version of the crate, but until then please enjoy this preview. - Also Fusha added better support for
union
types in the derive macros. I still don't know how any of the proc-macro stuff works at all, so please direct questions to her.
try_pod_read_unaligned
andpod_read_unaligned
let you go from&[u8]
toT:Pod
without worrying about alignment.
- Experimental support for the
portable_simd
language extension under thenightly_portable_simd
cargo feature. As the name implies, this is an experimental crate feature and it's not part of the semver contract. All it does is add the appropriateZeroable
andPod
impls.
- Why does this repo keep being hit with publishing problems? What did I do to deserve this curse, Ferris? This doesn't ever happen with tinyvec or fermium, only bytemuck.
- Soundness Fix: The wrap/peel methods for owned value conversion, added to
TransparentWrapper
in 1.6, can cause a double-drop if used with types that implDrop
. The fix was simply to add aManuallyDrop
layer around the value before doing thetransmute_copy
that is used to wrap/peel. While this fix could technically be backported to the 1.6 series, since 1.7 is semver compatible anyway the 1.6 series has simply been yanked.
- In response to Unsafe Code Guidelines Issue
#286, this
version of Bytemuck has a Soundness-Required Breaking Change. This is
"allowed" under Rust's backwards-compatibility guidelines, but it's still
annoying of course so we're trying to keep the damage minimal.
- The Reason: It turns out that pointer values should not have been
Pod
. More specifically,ptr as usize
is not the same operation as callingtransmute::<_, usize>(ptr)
. - LLVM has yet to fully sort out their story, but until they do, transmuting pointers can cause miscompilations. They may fix things up in the future, but we're not gonna just wait and have broken code in the mean time.
- The Fix: The breaking change is that the
Pod
impls for*const T
,*mut T
, andOption<NonNull<T>
are now gated behind theunsound_ptr_pod_impl
feature, which is off by default. - You are strongly discouraged from using this feature, but if a dependency of yours doesn't work when you upgrade to 1.7 because it relied on pointer casting, then you might wish to temporarily enable the feature just to get that dependency to build. Enabled features are global across all users of a given semver compatible version, so if you enable the feature in your own crate, your dependency will also end up getting the feature too, and then it'll be able to compile.
- Please move away from using this feature as soon as you can. Consider it to already be deprecated.
- PR 65
- The Reason: It turns out that pointer values should not have been
- Small goof with an errant
;
, so PR 69 actually got things working on SPIR-V.
cargo upload goof! ignore this one.
- The
TransparentWrapper
trait now has more methods. More ways to wrap, and now you can "peel" too! Note that we don't call it "unwrap" because that name is too strongly associated with the Option/Result methods. Thanks to LU15W1R7H for doing PR 58 - Min Const Generics! Now there's Pod and Zeroable for arrays of any size when
you turn on the
min_const_generics
crate feature. zakarumych got the work started in PR 59, and chorman0773 finished off the task in PR 63
- Fix
bytes_of
failing on zero sized types. PR 53
- Added
pod_collect_to_vec
, which will gather a slice into a vec, allowing you to change the pod type while also safely ignoring alignment. PR 50
- Kimundi fixed an issue that could make
try_zeroed_box
stack overflow for large values at low optimization levels. PR 43
- icewind1991 has contributed the proc-macros
for deriving impls of
Pod
,TransparentWrapper
,Zeroable
!! Everyone has been waiting for this one folks! It's a big deal. Just enable thederive
cargo feature and then you'll be able to derive the traits on your types. It generates all the appropriate tests for you. - The
zeroable_maybe_uninit
feature now adds aZeroable
impl to theMaybeUninit
type. This is only behind a feature flag becauseMaybeUninit
didn't exist back in1.34.0
(the minimum rust version ofbytemuck
).
- The entire crate is now available under the
Apache-2.0 OR MIT
license as well as the previousZlib
license #24. - HeroicKatora added the
try_zeroed_slice_box
function #10.zeroed_slice_box
is also available. - The
offset_of!
macro now supports a 2-arg version. For types that impl Default, it'll just make an instance usingdefault
and then call over to the 3-arg version. - The
PodCastError
type now supportsHash
andDisplay
. Also if you enable theextern_crate_std
feature then it will supportstd::error::Error
. - We now provide a
TransparentWrapper<T>
impl forcore::num::Wrapper<T>
. - The error type of
try_from_bytes
andtry_from_bytes_mut
when the input isn't aligned has been corrected from beingAlignmentMismatch
(intended for allocation casting only) toTargetAlignmentGreaterAndInputNotAligned
.
- Had a bug because the CI was messed up! It wasn't soundness related, because
it prevented the crate from building entirely if the
extern_crate_alloc
feature was used. Still, this is yanked, sorry.
- thomcc added many things:
- A fully sound
offset_of!
macro #10 - A
Contiguous
trait for when you've got enums with declared values all in a row #12 - A
TransparentWrapper
marker trait for when you want to more clearly enable adding and removing a wrapper struct to its inner value #15 - Now MIRI is run on CI in every single push! #16
- A fully sound
- SimonSapin added
from_bytes
,from_bytes_mut
,try_from_bytes
, andtry_from_bytes_mut
(PR Link)
- Changed to the zlib license.
- Added much more proper documentation.
- Reduced the minimum Rust version to 1.34