Add a safe way to create UninitSlice from slices (#598)

Introduce UninitSlice::from_slice and UninitSlice::from_uninit_slice
methods which safely create Uninit slice from provided slice of maybe
uninitialised or initialised memory.

In addition, add `From<&mut [T]>` implementations (for `T=u8` and
`T=MaybeUninit<u8>`) which do conversion from slice to UninitSlice.

Closes: #552
This commit is contained in:
Michal Nazarewicz
2023-02-09 17:24:23 +01:00
committed by GitHub
parent 74b04c7aae
commit 99a27542a0
2 changed files with 51 additions and 7 deletions
+1 -1
View File
@@ -1102,7 +1102,7 @@ unsafe impl BufMut for BytesMut {
if self.capacity() == self.len() {
self.reserve(64);
}
UninitSlice::from_slice(self.spare_capacity_mut())
self.spare_capacity_mut().into()
}
// Specialize these methods so they can skip checking `remaining_mut`