Skip to main content

poll_read_limited

Function poll_read_limited 

pub fn poll_read_limited<R>(
    reader: Pin<&mut R>,
    cx: &mut Context<'_>,
    buf: &mut ReadBuf<'_>,
    limit: usize,
) -> Poll<Result<usize, Error>>
where R: AsyncRead + ?Sized,
Available on crate feature std only.
Expand description

Poll reader once for at most limit bytes into the unfilled part of buf, and advance buf past the bytes read, returning their count.

The reader gets a [ReadBuf] of its own over that part, as [tokio::io::Take] does, so the result can be trusted whatever reader does with it.

§Panics

Panics if reader replaces the [ReadBuf] it is given with one over other memory.

§Safety-usable invariant

On Poll::Ready(Ok(n)): n is at most limit and at most buf.remaining() at the call, and buf was advanced by exactly n over bytes of its own buffer that are now initialized. On any other result the filled length of buf is unchanged. buf is never replaced.