Skip to content

Commit 3ddd2ef

Browse files
committed
Mention that casting to *const () is a way to roundtrip with from_raw_parts
1 parent b94bd12 commit 3ddd2ef

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/core/src/ptr/metadata.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ pub const fn metadata<T: PointeeSized>(ptr: *const T) -> <T as Pointee>::Metadat
106106
/// For slices, see the documentation of [`slice::from_raw_parts`] for safety requirements.
107107
/// For trait objects, the metadata must come from a pointer to the same underlying erased type.
108108
///
109+
/// If you are attempting to deconstruct a DST in a generic context to be reconstructed later,
110+
/// a thin pointer can always be obtained by casting `*const T` to `*const ()`.
111+
///
109112
/// [`slice::from_raw_parts`]: crate::slice::from_raw_parts
110113
#[unstable(feature = "ptr_metadata", issue = "81513")]
111114
#[inline]

0 commit comments

Comments
 (0)