bump_scope/polyfill/mod.rs
1//! Stuff that is missing from the msrv's std.
2//!
3//! This module also includes utility functions
4//! that are not from the standard library.
5#![expect(clippy::pedantic)]
6
7pub(crate) mod hint;
8pub(crate) mod iter;
9pub(crate) mod layout;
10pub(crate) mod non_null;
11pub(crate) mod pointer;
12pub(crate) mod slice;
13
14use core::mem::{ManuallyDrop, size_of};
15
16/// Not part of std.
17///
18/// A version of [`std::mem::transmute`] that can transmute between generic types.
19pub(crate) unsafe fn transmute_value<A, B>(a: A) -> B {
20 assert!(size_of::<A>() == size_of::<B>());
21 unsafe { core::mem::transmute_copy(&ManuallyDrop::new(a)) }
22}
23
24/// Not part of std.
25///
26/// A safer [`std::mem::transmute`].
27pub(crate) const unsafe fn transmute_ref<A, B>(a: &A) -> &B {
28 assert!(size_of::<A>() == size_of::<B>());
29 unsafe { &*(a as *const A).cast::<B>() }
30}
31
32/// Not part of std.
33///
34/// A safer [`std::mem::transmute`].
35pub(crate) unsafe fn transmute_mut<A, B>(a: &mut A) -> &mut B {
36 assert!(size_of::<A>() == size_of::<B>());
37 unsafe { &mut *(a as *mut A).cast::<B>() }
38}