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;
13pub(crate) mod usize;
14
15use core::mem::{ManuallyDrop, size_of};
16
17/// Not part of std.
18///
19/// A version of [`std::mem::transmute`] that can transmute between generic types.
20pub(crate) unsafe fn transmute_value<A, B>(a: A) -> B {
21    assert!(size_of::<A>() == size_of::<B>());
22    unsafe { core::mem::transmute_copy(&ManuallyDrop::new(a)) }
23}
24
25/// Not part of std.
26///
27/// A safer [`std::mem::transmute`].
28pub(crate) const unsafe fn transmute_ref<A, B>(a: &A) -> &B {
29    assert!(size_of::<A>() == size_of::<B>());
30    unsafe { &*(a as *const A).cast::<B>() }
31}
32
33/// Not part of std.
34///
35/// A safer [`std::mem::transmute`].
36pub(crate) unsafe fn transmute_mut<A, B>(a: &mut A) -> &mut B {
37    assert!(size_of::<A>() == size_of::<B>());
38    unsafe { &mut *(a as *mut A).cast::<B>() }
39}