pub unsafe fn take_read_buffer(
stash: &mut BytesMut,
read_size: usize,
) -> BytesMutExpand description
Take a read-sized scratch buffer from the front of stash, leaving the
remaining tail in stash to hand out on the next call.
This replaces the old bump-pointer read arena: successive reads carve
read_size chunks off one READ_SLAB_SIZE allocation until it is used up,
then a fresh slab is allocated. Freezing a returned buffer shares that
slab’s allocation (via bytes refcounting), so a lagging consumer pins the
slab exactly as the arena page did.
§Safety
The returned buffer reports read_size initialized bytes that are in fact
uninitialized, so it can be handed to an owned-buffer read without
zero-filling first. The caller must pass it straight to a read and
truncate it to the number of bytes actually read before freezing,
inspecting, or otherwise exposing its contents.