W3cubDocs

/Rust

Function from_raw_parts

pub const fn from_raw_parts<T>(
    data_pointer: *const impl Thin,
    metadata: <T as Pointee>::Metadata,
) -> *const Twhere
    T: ?Sized,
🔬This is a nightly-only experimental API. (ptr_metadata #81513)

Forms a (possibly-wide) raw pointer from a data pointer and metadata.

This function is safe but the returned pointer is not necessarily safe to dereference. 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 ().

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/ptr/fn.from_raw_parts.html