Function presser::get_maybe_uninit_slice_at_offset_mut
source · pub fn get_maybe_uninit_slice_at_offset_mut<'a, T, S: Slab + ?Sized>(
slab: &'a mut S,
offset: usize,
len: usize
) -> Result<&'a mut [MaybeUninit<T>], Error>Expand description
Gets a &mut [MaybeUninit<T>] within slab at offset.
offsetis the offset, in bytes, after the start ofslabat which a[T; len]may be placed.lenis the length of the returned slice, counted in elements ofT.
The function will return an error if:
offsetwithinslabis not properly aligned forToffsetis out of bounds of theslaboffset + size_of::<T> * lenis out of bounds of theslab
Safety
This function is safe since in order to read any data you need to call the unsafe MaybeUninit::assume_init on the returned value.
However, you should know that if you do that, you must have ensured that there is indeed a valid* T in its place.
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.