aboutsummaryrefslogtreecommitdiff
path: root/tests/test_bytes_odd_alloc.rs
diff options
context:
space:
mode:
authorGravatar Anthony Ramine <123095+nox@users.noreply.github.com> 2024-05-28 10:14:02 +0200
committerGravatar GitHub <noreply@github.com> 2024-05-28 10:14:02 +0200
commitfa1daac3ae1dcb07dffe3a41a041dffd6edf177b (patch)
tree5f35204d0b1e5d89e3c8fa53c59c5c363694b58f /tests/test_bytes_odd_alloc.rs
parentcaf520ac7f2c466d26bd88eca33ddc53c408e17e (diff)
downloadbytes-fa1daac3ae1dcb07dffe3a41a041dffd6edf177b.tar.gz
bytes-fa1daac3ae1dcb07dffe3a41a041dffd6edf177b.tar.zst
bytes-fa1daac3ae1dcb07dffe3a41a041dffd6edf177b.zip
Change Bytes::make_mut to impl From<Bytes> for BytesMut (closes #709) (#710)HEADmaster
<Arc<T>>::make_mut returns a &mut T, such an API is doable for Bytes too and thus we should reserve Bytes::make_mut for that. Furthermore, it would be helpful to use From<Bytes> as a trait bound in some cases with other traits such as Hyper's body trait, where Hyper gives you Bytes values. Finally, making it impl From<Bytes> for BytesMut means the API is more easily discoverable as it appears on both Bytes and BytesMut.
Diffstat (limited to 'tests/test_bytes_odd_alloc.rs')
-rw-r--r--tests/test_bytes_odd_alloc.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/tests/test_bytes_odd_alloc.rs b/tests/test_bytes_odd_alloc.rs
index 8008a0e..4758dc2 100644
--- a/tests/test_bytes_odd_alloc.rs
+++ b/tests/test_bytes_odd_alloc.rs
@@ -6,7 +6,7 @@
use std::alloc::{GlobalAlloc, Layout, System};
use std::ptr;
-use bytes::Bytes;
+use bytes::{Bytes, BytesMut};
#[global_allocator]
static ODD: Odd = Odd;
@@ -97,50 +97,50 @@ fn test_bytes_into_vec() {
}
#[test]
-fn test_bytes_make_mut_vec() {
+fn test_bytesmut_from_bytes_vec() {
let vec = vec![33u8; 1024];
// Test case where kind == KIND_VEC
let b1 = Bytes::from(vec.clone());
- let b1m = b1.make_mut();
+ let b1m = BytesMut::from(b1);
assert_eq!(b1m, vec);
}
#[test]
-fn test_bytes_make_mut_arc_1() {
+fn test_bytesmut_from_bytes_arc_1() {
let vec = vec![33u8; 1024];
// Test case where kind == KIND_ARC, ref_cnt == 1
let b1 = Bytes::from(vec.clone());
drop(b1.clone());
- let b1m = b1.make_mut();
+ let b1m = BytesMut::from(b1);
assert_eq!(b1m, vec);
}
#[test]
-fn test_bytes_make_mut_arc_2() {
+fn test_bytesmut_from_bytes_arc_2() {
let vec = vec![33u8; 1024];
// Test case where kind == KIND_ARC, ref_cnt == 2
let b1 = Bytes::from(vec.clone());
let b2 = b1.clone();
- let b1m = b1.make_mut();
+ let b1m = BytesMut::from(b1);
assert_eq!(b1m, vec);
// Test case where vtable = SHARED_VTABLE, kind == KIND_ARC, ref_cnt == 1
- let b2m = b2.make_mut();
+ let b2m = BytesMut::from(b2);
assert_eq!(b2m, vec);
}
#[test]
-fn test_bytes_make_mut_arc_offset() {
+fn test_bytesmut_from_bytes_arc_offset() {
let vec = vec![33u8; 1024];
// Test case where offset != 0
let mut b1 = Bytes::from(vec.clone());
let b2 = b1.split_off(20);
- let b1m = b1.make_mut();
- let b2m = b2.make_mut();
+ let b1m = BytesMut::from(b1);
+ let b2m = BytesMut::from(b2);
assert_eq!(b2m, vec[20..]);
assert_eq!(b1m, vec[..20]);