Skip to main content

try_zeroed_bytes

Function try_zeroed_bytes 

Source
pub fn try_zeroed_bytes(len: usize) -> Option<Box<[u8]>>
Expand description

A zeroed len-byte heap buffer, or None if the allocator is exhausted.

The fallible form of vec![0u8; len].into_boxed_slice(), which aborts through the same OOM hook as Box::new. try_reserve_exact is stable; the capacity it records is exactly len, so into_boxed_slice does not reallocate.