Conversation
Co-authored-by: Alice Ryhl <aliceryhl@google.com>
Buf impl for VecDeque<Bytes>Buf impl for VecDeque<impl Buf>
change `let .. else ..` to `expect`
| fn chunk(&self) -> &[u8] { | ||
| if let Some(b) = self.front() { | ||
| b.chunk() | ||
| } else { | ||
| &[] | ||
| } | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
I see what you mean, let me try to make it follow the contract.
There was a problem hiding this comment.
If we need a bugfix to existing code, it should be a separate PR.
Co-authored-by: Paolo Barbolini <paolo@paolo565.org>
| for buf in self { | ||
| if n >= dst.len() { | ||
| break; | ||
| } | ||
| n += buf.chunks_vectored(&mut dst[n..]); |
There was a problem hiding this comment.
This loop must exit if the chunks written by buf have a combined length smaller than buf.remaining(), because you must read everything from the first buffer before you start reading from the second buffer. Please add a test that would have caught this.
There was a problem hiding this comment.
The access issue should be fixed now. Let me know if I missed anything.
This prevents subsequent buffers from being incorrectly processed before the current buffer's remaining data.
src/buf/vec_deque.rs
Outdated
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Tests go in tests/ directory outside of src/ unless they have to be here.
This PR adds an implementation of the
Buftrait forVecDeque<impl Buf>.Sometimes we need to store multiple non-contiguous
Bytesat runtime. UsingChaincan be limiting because it doesn't provide a concrete type for a collection of buffers. ImplementingBufforVecDeque<impl Buf>gives a handy way to view these disjoint chunks as a single logical buffer.Update:
Bufis implemented forVecDeque<impl Buf>instead ofVecDeque<Bytes>.chunks_vectoredforVecDeque<impl Buf>remaining()is 0chunks_vectored()