Mini-redis: What prevents the buffer from growing infinitely?


I’m reading the mini-redis frame reading implementation and have trouble understanding why the read buffer does not grow to infinity.

Here bytes from the stream are read into buffer, which is a BytesMut, so it can grow to any size:

if 0 == self.buffer).await? {

New frames are all simply appended to this buffer for ever.

I did notice that on every attempt to parse a frame, Buf::advance is called on the buffer:


Wouldn’t that just advance the left bound of the view into the underlying buffer? Or is an implementation detail here being made use of? Or some other aspect whose doc I overlooked?

Thank you.

When you call read_buf on a BytesMut that has already reached the end of its allocation, a new allocation is created. This new allocation will not include the data that it has advanced past.