Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More TransparentWrapper impls (core::cmp::Reverse and core::num::Saturating) #269

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ aarch64_simd = [] # MSRV 1.59.0: support aarch64 simd types

must_cast = [] # MSRV 1.64.0: support the `must` module.

# Adds `TransparentWrapper` impls for stdlib types newer than bytemuck's base MSRV.
# Current MSRV 1.74.0: `core::num::Saturating`.
# MSRV may increase if impls are added for newer types.
transparentwrapper_extra = []

const_zeroed = [] # MSRV 1.75.0: support const `zeroed()`

# Do not use if you can avoid it, because this is **unsound**!!!!
Expand Down
17 changes: 17 additions & 0 deletions src/transparent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,20 @@ pub unsafe trait TransparentWrapper<Inner: ?Sized> {
}

unsafe impl<T> TransparentWrapper<T> for core::num::Wrapping<T> {}
#[cfg(feature = "transparentwrapper_extra")]
#[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "transparentwrapper_extra"))
)]
unsafe impl<T> TransparentWrapper<T> for core::num::Saturating<T> {}

// Note that `Reverse` existed since Rust 1.19.0, but was only made `#[repr(transparent)]`
// in Rust 1.52.0 (PR: https://github.com/rust-lang/rust/pull/81879), so we have it under
// the same feature as `Saturating`, which was stabilized in Rust 1.74.0, so that this
// impl cannot be used on a version before 1.52.0 where it would be unsound.
#[cfg(feature = "transparentwrapper_extra")]
#[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "transparentwrapper_extra"))
)]
unsafe impl<T> TransparentWrapper<T> for core::cmp::Reverse<T> {}
Loading