pub unsafe fn get_maybe_uninit_slice_at_offset_mut_unchecked<'a, T, S: Slab + ?Sized>(
slab: &'a mut S,
offset: usize,
len: usize
) -> &'a mut [MaybeUninit<T>]
Expand description
Gets a &mut [MaybeUninit<T>]
within slab
at offset
, not checking any requirements.
offset
is the offset, in bytes, after the start ofslab
at which a[T; len]
is placed.len
is the length of the returned slice, counted in elements ofT
.
Safety
You must ensure:
offset
withinslab
is properly aligned forT
offset
is within bounds of theslab
offset + size_of::<T> * len
is within bounds of theslab
- See also safety docs of
core::slice::from_raw_parts_mut
.
You must have ensured there is a fully-initialized and valid* T
in each returned MaybeUninit<T>
before calling MaybeUninit::assume_init
.
Note that if you write through the returned reference, any padding bytes within the layout of T
(which for a repr(Rust)
type is arbitrary and unknown) must thereafter be considered uninitialized
until you explicitly initialize them again. This means that if you write a T
which contains
padding into slab
, you must not, for example, try to read those bytes as &[u8]
afterwards
(or as some other type which expects those bytes to be initialized), as you would then be
reading uninitialized memory, which is undefined behavior.
* Validity is a complex topic not to be taken lightly. See this rust reference page for more details.