mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-27 00:00:17 +02:00
Impl Extend for BytesMut
This commit is contained in:
@@ -1298,6 +1298,28 @@ impl<'a> IntoIterator for &'a BytesMut {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Extend<u8> for BytesMut {
|
||||||
|
fn extend<T>(&mut self, iter: T) where T: IntoIterator<Item = u8> {
|
||||||
|
let iter = iter.into_iter();
|
||||||
|
|
||||||
|
let (lower, _) = iter.size_hint();
|
||||||
|
self.reserve(lower);
|
||||||
|
|
||||||
|
for b in iter {
|
||||||
|
unsafe {
|
||||||
|
self.bytes_mut()[0] = b;
|
||||||
|
self.advance_mut(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Extend<&'a u8> for BytesMut {
|
||||||
|
fn extend<T>(&mut self, iter: T) where T: IntoIterator<Item = &'a u8> {
|
||||||
|
self.extend(iter.into_iter().map(|b| *b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* ===== Inner =====
|
* ===== Inner =====
|
||||||
|
|||||||
@@ -290,6 +290,13 @@ fn inline_storage() {
|
|||||||
assert_eq!(*bytes, zero[0..inline_cap()]);
|
assert_eq!(*bytes, zero[0..inline_cap()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn extend() {
|
||||||
|
let mut bytes = BytesMut::with_capacity(0);
|
||||||
|
bytes.extend(LONG);
|
||||||
|
assert_eq!(*bytes, LONG[..]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stress() {
|
fn stress() {
|
||||||
// Tests promoting a buffer from a vec -> shared in a concurrent situation
|
// Tests promoting a buffer from a vec -> shared in a concurrent situation
|
||||||
|
|||||||
Reference in New Issue
Block a user