-
Notifications
You must be signed in to change notification settings - Fork 332
Adds Buf impl for VecDeque<impl Buf>
#822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
80647bb
94f0950
ea8d166
c1e91a4
ee4ce5d
2aa7fb0
de6884b
16bd51e
2d094c4
9ce4dee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,3 +38,45 @@ impl Buf for VecDeque<u8> { | |
| self.drain(..cnt); | ||
| } | ||
| } | ||
|
|
||
| impl<T: Buf> Buf for VecDeque<T> { | ||
| fn remaining(&self) -> usize { | ||
| self.iter().map(|b| b.remaining()).sum() | ||
| } | ||
|
|
||
| fn chunk(&self) -> &[u8] { | ||
| if let Some(b) = self.front() { | ||
| b.chunk() | ||
| } else { | ||
| &[] | ||
| } | ||
| } | ||
|
Comment on lines
+47
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| #[cfg(feature = "std")] | ||
| fn chunks_vectored<'a>(&'a self, dst: &mut [io::IoSlice<'a>]) -> usize { | ||
| let mut n = 0; | ||
| for buf in self { | ||
| if n >= dst.len() { | ||
| break; | ||
| } | ||
| n += buf.chunks_vectored(&mut dst[n..]); | ||
|
Comment on lines
+57
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop must exit if the chunks written by
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The access issue should be fixed now. Let me know if I missed anything. |
||
| } | ||
| n | ||
| } | ||
|
|
||
| fn advance(&mut self, mut cnt: usize) { | ||
| while cnt > 0 { | ||
| let Some(b) = self.front_mut() else { | ||
| panic!("advance called with cnt > remaining"); | ||
| }; | ||
|
b01o marked this conversation as resolved.
Outdated
|
||
| let rem = b.remaining(); | ||
| if cnt < rem { | ||
| b.advance(cnt); | ||
| return; | ||
| } else { | ||
| cnt -= rem; | ||
| self.pop_front(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.