Function uninit_tools::cast_init_to_uninit_slice_mut[][src]

pub unsafe fn cast_init_to_uninit_slice_mut<U>(
    init: &mut [U]
) -> &mut [MaybeUninit<U>]

Notable traits for &'_ [u8]

impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]

Cast a mutable slice of bytes into a slice of uninitialized bytes, pretending that it is uninitialized. This is completely safe since they always have the same memory layout; however, the layout of the slices themselves must not be relied upon. The initializedness information is lost as part of this cast, but can be recovered when initializing again or by using unsafe code.

Safety

This is unsafe, since it allows a slice which is borrowed for a lifetime possibly shorter than 'static, to be reused after the MaybeUninit slice has had MaybeUninit::uninit() values written to it. For this to be safe, the caller must only write initialized bytes to the returned slice.

This function is only meant to be used in generic contexts, unlike cast_init_to_uninit_slice, which is used more often when copying initialized bytes to uninitialized bytes.