From 3ddd2ef8c518efe10c811a229f056e96864d83c1 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 2 Jul 2025 13:15:07 -0700 Subject: [PATCH] Mention that casting to *const () is a way to roundtrip with from_raw_parts --- library/core/src/ptr/metadata.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/ptr/metadata.rs b/library/core/src/ptr/metadata.rs index 0deac3621e84c..dc3ec3fd19945 100644 --- a/library/core/src/ptr/metadata.rs +++ b/library/core/src/ptr/metadata.rs @@ -106,6 +106,9 @@ pub const fn metadata(ptr: *const T) -> ::Metadat /// For slices, see the documentation of [`slice::from_raw_parts`] for safety requirements. /// For trait objects, the metadata must come from a pointer to the same underlying erased type. /// +/// If you are attempting to deconstruct a DST in a generic context to be reconstructed later, +/// a thin pointer can always be obtained by casting `*const T` to `*const ()`. +/// /// [`slice::from_raw_parts`]: crate::slice::from_raw_parts #[unstable(feature = "ptr_metadata", issue = "81513")] #[inline]