Skip to content

Commit af8d110

Browse files
zachs18Lokathor
andauthored
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 <[email protected]>
1 parent 79a15d0 commit af8d110

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ aarch64_simd = [] # MSRV 1.59.0: support aarch64 simd types
4040

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

43+
# Adds `TransparentWrapper` impls for stdlib types newer than bytemuck's base MSRV.
44+
# Current MSRV 1.74.0: `core::num::Saturating`.
45+
# MSRV may increase if impls are added for newer types.
46+
transparentwrapper_extra = []
47+
4348
const_zeroed = [] # MSRV 1.75.0: support const `zeroed()`
4449

4550
# Do not use if you can avoid it, because this is **unsound**!!!!

src/transparent.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,20 @@ pub unsafe trait TransparentWrapper<Inner: ?Sized> {
303303
}
304304

305305
unsafe impl<T> TransparentWrapper<T> for core::num::Wrapping<T> {}
306+
#[cfg(feature = "transparentwrapper_extra")]
307+
#[cfg_attr(
308+
feature = "nightly_docs",
309+
doc(cfg(feature = "transparentwrapper_extra"))
310+
)]
311+
unsafe impl<T> TransparentWrapper<T> for core::num::Saturating<T> {}
312+
313+
// Note that `Reverse` existed since Rust 1.19.0, but was only made `#[repr(transparent)]`
314+
// in Rust 1.52.0 (PR: https://github.com/rust-lang/rust/pull/81879), so we have it under
315+
// the same feature as `Saturating`, which was stabilized in Rust 1.74.0, so that this
316+
// impl cannot be used on a version before 1.52.0 where it would be unsound.
317+
#[cfg(feature = "transparentwrapper_extra")]
318+
#[cfg_attr(
319+
feature = "nightly_docs",
320+
doc(cfg(feature = "transparentwrapper_extra"))
321+
)]
322+
unsafe impl<T> TransparentWrapper<T> for core::cmp::Reverse<T> {}

0 commit comments

Comments
 (0)