mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-24 00:00:14 +02:00
Implement Extend<Bytes> for BytesMut (#527)
This commit is contained in:
@@ -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 {
|
impl FromIterator<u8> for BytesMut {
|
||||||
fn from_iter<T: IntoIterator<Item = u8>>(into_iter: T) -> Self {
|
fn from_iter<T: IntoIterator<Item = u8>>(into_iter: T) -> Self {
|
||||||
BytesMut::from_vec(Vec::from_iter(into_iter))
|
BytesMut::from_vec(Vec::from_iter(into_iter))
|
||||||
|
|||||||
@@ -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]
|
#[test]
|
||||||
fn extend_mut_without_size_hint() {
|
fn extend_mut_without_size_hint() {
|
||||||
let mut bytes = BytesMut::with_capacity(0);
|
let mut bytes = BytesMut::with_capacity(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user