Skip to main content

peek_input_until_with_options

Function peek_input_until_with_options 

pub async fn peek_input_until_with_options<R, O, P>(
    reader: &mut R,
    buffer: &mut [u8],
    offset: usize,
    timeout: Option<Duration>,
    max_attempts: Option<NonZero<usize>>,
    predicate: P,
) -> PeekOutput<O>
where R: AsyncRead + Unpin, P: Fn(&[u8]) -> Option<O>,
Expand description

Same as peek_input_until but with explicit control over the starting offset and the read-attempt budget.

max_attempts:

  • Some(n) — stop after n read attempts even if the predicate did not match.
  • None — no attempt cap; rely on the reader’s EOF and the optional timeout.

The default budget used by peek_input_until and peek_input_until_with_offset is derived from the buffer length (max(buffer.len() / 4, 1) + 1), which is a reasonable fallback for sizable buffers but can be too tight for small protocol- sniffing buffers under TCP fragmentation. Prefer this function with an explicit budget when reading from untrusted/proxied peers.