Skip to main content

read_exact_uninit

Function read_exact_uninit 

Source
pub async fn read_exact_uninit<R>(reader: &mut R, len: usize) -> Result<Vec<u8>>
where R: AsyncRead + Unpin,
Expand description

Read exactly len bytes from an async reader without zero-initializing the buffer first.

This avoids the double-write overhead of vec![0u8; len] followed by read_exact — the zeroing is wasted work since every byte is immediately overwritten by the read. For large payloads this can yield measurable performance gains.

The returned Vec has exactly len initialized bytes.

§Errors

Returns io::Error if the underlying reader’s read_exact fails (e.g., unexpected EOF before len bytes are read).