4 ms·
> Rust makes the caller allocate the buffer for reads. I don't think this is true in this context. The buffer initially will have a capacity of 0, and will gro
by MrJohz 3y ago
> Rust makes the caller allocate the buffer for reads.
I don't think this is true in this context. The buffer initially will have a capacity of 0, and will grow to fit the available data, so that as read_to_end is inserting data, the buffer will be resized until all the data fits.
However, if we had preallocated the buffer, or were reusing an existing buffer, then the buffer would only be grown if the data being read was too large for the buffer. In addition, there are other functions that can will never resize the buffer, and read only until the buffer is filled.
Perhaps a better way of phrasing this is that Rust lets the caller control where the data will be written to.
- cbarrick 3y agoFair. "Allocate" is the wrong word. For the sake of a terse inline comment, it might be better to just s/allocate/create/.