aboutsummaryrefslogtreecommitdiff
path: root/tests/test_bytes.rs
diff options
context:
space:
mode:
authorGravatar Sean McArthur <sean@seanmonstar.com> 2019-10-24 14:40:45 -0700
committerGravatar GitHub <noreply@github.com> 2019-10-24 14:40:45 -0700
commit2ac72333fa2a7c2e50bf68c4db998bcd7f493415 (patch)
tree61cddc535df536e119780fcf1f3529167c400653 /tests/test_bytes.rs
parentfe2183dc2fa126e81c8af23f7096a1fcb05d6d1a (diff)
downloadbytes-2ac72333fa2a7c2e50bf68c4db998bcd7f493415.tar.gz
bytes-2ac72333fa2a7c2e50bf68c4db998bcd7f493415.tar.zst
bytes-2ac72333fa2a7c2e50bf68c4db998bcd7f493415.zip
Change BufMut methods that expose maybe-uninitialized bytes (#305)
- The return type of `BufMut::bytes_mut` is now `&mut [MaybeUninit<u8>]`. - The argument type of `BufMut::bytes_vectored_mut` is now `&mut [bytes::buf::IoSliceMut]`. - `bytes::buf::IoSliceMut` is a `repr(transparent)` wrapper around an `std::io::IoSliceMut`, but does not expose the inner bytes with a safe API, since they might be uninitialized. - `BufMut::bytesMut` and `BufMut::bytes_vectored_mut` are no longer `unsafe fn`, since the types encapsulate the unsafety instead.
Diffstat (limited to 'tests/test_bytes.rs')
-rw-r--r--tests/test_bytes.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs
index 212189e..9fa8019 100644
--- a/tests/test_bytes.rs
+++ b/tests/test_bytes.rs
@@ -465,6 +465,16 @@ fn extend_from_slice_mut() {
}
#[test]
+fn extend_mut_without_size_hint() {
+ let mut bytes = BytesMut::with_capacity(0);
+ let mut long_iter = LONG.iter();
+
+ // Use iter::from_fn since it doesn't know a size_hint
+ bytes.extend(std::iter::from_fn(|| long_iter.next()));
+ assert_eq!(*bytes, LONG[..]);
+}
+
+#[test]
fn from_static() {
let mut a = Bytes::from_static(b"ab");
let b = a.split_off(1);