Skip to content
Snippets Groups Projects
Unverified Commit b68fa46e authored by Carl Lerche's avatar Carl Lerche
Browse files

Fix panic in FromIterator for BytesMut

parent ef09e98f
No related branches found
No related tags found
No related merge requests found
...@@ -869,6 +869,7 @@ impl FromIterator<u8> for BytesMut { ...@@ -869,6 +869,7 @@ impl FromIterator<u8> for BytesMut {
let mut out = BytesMut::with_capacity(maybe_max.unwrap_or(min)); let mut out = BytesMut::with_capacity(maybe_max.unwrap_or(min));
for i in iter { for i in iter {
out.reserve(1);
out.put(i); out.put(i);
} }
......
...@@ -674,3 +674,24 @@ fn unsplit_two_split_offs() { ...@@ -674,3 +674,24 @@ fn unsplit_two_split_offs() {
buf.unsplit(buf2); buf.unsplit(buf2);
assert_eq!(b"aaaabbbbccccdddd", &buf[..]); assert_eq!(b"aaaabbbbccccdddd", &buf[..]);
} }
#[test]
fn from_iter_no_size_hint() {
use std::iter;
let mut expect = vec![];
let actual: Bytes = iter::repeat(b'x')
.scan(100, |cnt, item| {
if *cnt >= 1 {
*cnt -= 1;
expect.push(item);
Some(item)
} else {
None
}
})
.collect();
assert_eq!(&actual[..], &expect[..]);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment