pub unsafe fn read_slice_at_offset_mut<'a, T, S: Slab + ?Sized>(
    slab: &'a mut S,
    offset: usize,
    len: usize
) -> Result<&'a mut [T], Error>
Expand description

Reads a &mut [T] within slab at offset.

  • offset is the offset, in bytes, after the start of slab at which a [T; len] is placed.
  • len is the length of the returned slice, counted in elements of T.

The function will return an error if:

  • offset within slab is not properly aligned for T
  • offset is out of bounds of the slab
  • offset + size_of::<T> * len is out of bounds of the slab

Safety

You must have previously fully-initialized a valid* [T; len] at the given offset into slab. If you want to fill an uninitialized buffer with data, you should instead use any of the copy helper functions or one of the maybe_uninit_mut read functions.

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.