On this page
Function std::slice::from_raw_parts_mut
pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T]
Performs the same functionality as from_raw_parts
, except that a mutable slice is returned.
Safety
Behavior is undefined if any of the following conditions are violated:
data
must be valid for both reads and writes forlen * mem::size_of::<T>()
many bytes, and it must be properly aligned. This means in particular:- The entire memory range of this slice must be contained within a single allocated object! Slices can never span across multiple allocated objects.
data
must be non-null and aligned even for zero-length slices. One reason for this is that enum layout optimizations may rely on references (including slices of any length) being aligned and non-null to distinguish them from other data. You can obtain a pointer that is usable asdata
for zero-length slices usingNonNull::dangling()
.
data
must point tolen
consecutive properly initialized values of typeT
.The memory referenced by the returned slice must not be accessed through any other pointer (not derived from the return value) for the duration of lifetime
'a
. Both read and write accesses are forbidden.The total size
len * mem::size_of::<T>()
of the slice must be no larger thanisize::MAX
, and adding that size todata
must not “wrap around” the address space. See the safety documentation ofpointer::offset
.
© 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/slice/fn.from_raw_parts_mut.html