Add test for copy_to_bytes() -> BytesMut avoiding clone (#809)

This commit is contained in:
Alice Ryhl
2025-12-02 13:08:19 +01:00
committed by GitHub
parent 94e42915a9
commit b4ed70daee
+11
View File
@@ -448,3 +448,14 @@ fn test_deref_buf_forwards() {
assert_eq!((Box::new(Special) as Box<dyn Buf>).get_u8(), b'x'); assert_eq!((Box::new(Special) as Box<dyn Buf>).get_u8(), b'x');
assert_eq!(Box::new(Special).get_u8(), b'x'); assert_eq!(Box::new(Special).get_u8(), b'x');
} }
#[test]
fn copy_to_bytes_mut() {
let mut bytes_mut = BytesMut::from(b"foobar".as_slice());
let ptr = bytes_mut.as_ptr();
let ret = bytes_mut.copy_to_bytes(bytes_mut.len());
assert_eq!(ret.as_ptr(), ptr);
drop(bytes_mut);
let bytes_mut2 = BytesMut::from(ret);
assert_eq!(bytes_mut2.as_ptr(), ptr);
}