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