Skip to content
30 changes: 30 additions & 0 deletions src/buf/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ impl Buf for VecDeque<u8> {
self.drain(..cnt);
}
}

impl Buf for VecDeque<crate::Bytes> {
Comment thread
b01o marked this conversation as resolved.
Outdated
fn remaining(&self) -> usize {
self.iter().map(|b| b.remaining()).sum()
}

fn chunk(&self) -> &[u8] {
Comment thread
b01o marked this conversation as resolved.
if let Some(b) = self.front() {
b.chunk()
} else {
&[]
}
}
Comment on lines +47 to +52
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think of it more, this violates the implementer notes on chunk(). Since we accept any VecDeque, there could be empty elements within it, something that common BufList implementations prevent 1 2

chunk() should return an empty slice if and only if remaining() returns 0

Footnotes

  1. https://docs.rs/crate/hyper/1.8.1/source/src/common/buf.rs#17-21

  2. https://docs.rs/crate/watermelon-proto/0.1.8/source/src/util/buf_list.rs#22-27

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, let me try to make it follow the contract.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need a bugfix to existing code, it should be a separate PR.


fn advance(&mut self, mut cnt: usize) {
while cnt > 0 {
let Some(b) = self.front_mut() else {
panic!("advance called with cnt > remaining");
};
Comment thread
b01o marked this conversation as resolved.
Outdated
let rem = b.remaining();
if cnt < rem {
b.advance(cnt);
return;
} else {
cnt -= rem;
self.pop_front();
}
}
}
}
Loading