Expand description
Utilities to help make copying data around into raw, possibly-uninitialized buffers easier and safer.
The main idea is to have Slab implemented on buffer-types for which it is safe
to do, which then enables the use of the other functions within the crate.
See RawAllocation and BorrowedRawAllocation for built-in generic types that can be used
to easily gain access to a type implementing Slab for a raw allocation or a custom
buffer type.
Safety
Note that obeying the safety rules specified in the Slab safety documentation
only guarantees safety for the direct results of the copy operations performed by the
helper functions exported at the crate root (and the safe functions on Slab). However,
it is not guaranteed that operations which would previously have been safe to perform
using same backing memory that the Slab you copied into used are still safe.
For example, say you have a fully-initialized
chunk of bytes (like a Vec<u8>), which you view as a Slab, and then (safely) perform a copy
operation into using copy_to_offset. If the T you copied into it has any padding bytes in
its memory layout, then the memory locations where those padding bytes now exist in the underlying Vec’s
memory must now be treated as uninitialized. As such, taking any view into that byte vector which
relies on those newly-uninit bytes being initialized to be valid (for example, taking a &[u8] slice of the Vec
which includes those bytes, even if your code never actually reads from that slice)
is now instant undefined behavior.
Structs
Enums
Traits
Functions
src to dst, returning a mutable reference to the now initialized contents of dst.
Any already initialized elements will not be dropped.src iterator into the memory represented by dst starting at a minimum location
of start_offset bytes past the start of dst.copy_from_iter_to_offset_with_align except that
alignment between elements yielded by the iterator will ignore min_alignment
and rather only be aligned to the alignment of T.slice into the memory represented by self starting at a minimum location
of start_offset bytes past the start of self.slice into the memory represented by self starting at a minimum location
of start_offset bytes past the start of self.src to dst, returning a mutable reference to the now initialized contents of dst.src into the memory represented by dst starting at a minimum location
of start_offset bytes past the start of dst.src into the memory represented by dst starting at a minimum location
of start_offset bytes past the start of dst and with minimum alignment
min_alignment.Vec and unsafely resizes it to the given length, returning a mutable slice to MaybeUninit<T> for each
item in the newly-resized Vec.