Implement Extend<Bytes> for BytesMut (#527)

This commit is contained in:
Rob Ede
2022-01-24 09:58:18 +01:00
committed by GitHub
parent 0e3b2466f1
commit 131dae161f
2 changed files with 18 additions and 0 deletions
+11
View File
@@ -1211,6 +1211,17 @@ impl<'a> Extend<&'a u8> for BytesMut {
}
}
impl Extend<Bytes> for BytesMut {
fn extend<T>(&mut self, iter: T)
where
T: IntoIterator<Item = Bytes>,
{
for bytes in iter {
self.extend_from_slice(&bytes)
}
}
}
impl FromIterator<u8> for BytesMut {
fn from_iter<T: IntoIterator<Item = u8>>(into_iter: T) -> Self {
BytesMut::from_vec(Vec::from_iter(into_iter))
+7
View File
@@ -544,6 +544,13 @@ fn extend_from_slice_mut() {
}
}
#[test]
fn extend_mut_from_bytes() {
let mut bytes = BytesMut::with_capacity(0);
bytes.extend([Bytes::from(LONG)]);
assert_eq!(*bytes, LONG[..]);
}
#[test]
fn extend_mut_without_size_hint() {
let mut bytes = BytesMut::with_capacity(0);