aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGravatar Bryan Donlan <bdonlan@amazon.com> 2020-07-08 20:38:54 +0000
committerGravatar Sean McArthur <sean@seanmonstar.com> 2020-07-08 15:28:36 -0700
commit81550da474bcd243b9e8765c6555831310a954e8 (patch)
tree57f8c193605bd304479958da5297f545c783cc78 /tests
parent90e7e650c99b6d231017d9b831a01e95b8c06756 (diff)
downloadbytes-81550da474bcd243b9e8765c6555831310a954e8.tar.gz
bytes-81550da474bcd243b9e8765c6555831310a954e8.tar.zst
bytes-81550da474bcd243b9e8765c6555831310a954e8.zip
BytesMut: Reuse buffer when data fully consumed via Buf
Closes #412
Diffstat (limited to 'tests')
-rw-r--r--tests/test_bytes.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_bytes.rs b/tests/test_bytes.rs
index 106fa6f..bbe51f5 100644
--- a/tests/test_bytes.rs
+++ b/tests/test_bytes.rs
@@ -930,6 +930,22 @@ fn bytes_buf_mut_advance() {
}
#[test]
+fn bytes_buf_mut_reuse_when_fully_consumed() {
+ use bytes::{Buf, BytesMut};
+ let mut buf = BytesMut::new();
+ buf.reserve(8192);
+ buf.extend_from_slice(&[0u8; 100][..]);
+
+ let p = &buf[0] as *const u8;
+ buf.advance(100);
+
+ buf.reserve(8192);
+ buf.extend_from_slice(b" ");
+
+ assert_eq!(&buf[0] as *const u8, p);
+}
+
+#[test]
#[should_panic]
fn bytes_reserve_overflow() {
let mut bytes = BytesMut::with_capacity(1024);