pub fn empty_from_maybeuninit_slice<T>(
slot: &mut [MaybeUninit<T>],
) -> OwningSlice<'_, T>Expand description
Create a OwningSlice<'a, T> with a length of 0 from a &'a mut [MaybeUninit<T>]>. The capacity is the length of the given slice.
The slice elements are not assumed to be initialized, so this is not an
unsafe function.
ยงExamples
use noop_allocator::owning_slice;
let mut buf: [MaybeUninit<String>; 4] = [const { MaybeUninit::uninit() }; 4];
let mut vec = owning_slice::empty_from_maybeuninit_slice(&mut buf);
assert!(vec.is_empty());
assert_eq!(vec.capacity(), 4);
vec.push("Hello, world!".to_string());
assert_eq!(vec, ["Hello, world!"]);