mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-19 00:00:12 +02:00
chore: add safety comments on unsafe blocks (#827)
This commit is contained in:
@@ -1543,6 +1543,65 @@ fn split_to_empty_addr_mut() {
|
||||
let _ = &buf[..];
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes_mut_split_boundary_capacities() {
|
||||
// VEC mode
|
||||
for at in [0, 5, 11] {
|
||||
let mut buf = BytesMut::with_capacity(64);
|
||||
buf.extend_from_slice(b"hello world");
|
||||
|
||||
let other = buf.split_off(at);
|
||||
assert_eq!(
|
||||
buf.capacity() + other.capacity(),
|
||||
64,
|
||||
"split_off at {} should preserve total capacity",
|
||||
at
|
||||
);
|
||||
}
|
||||
|
||||
for at in [0, 5, 11] {
|
||||
let mut buf = BytesMut::with_capacity(64);
|
||||
buf.extend_from_slice(b"hello world");
|
||||
|
||||
let other = buf.split_to(at);
|
||||
assert_eq!(
|
||||
buf.capacity() + other.capacity(),
|
||||
64,
|
||||
"split_to at {} should preserve total capacity",
|
||||
at
|
||||
);
|
||||
}
|
||||
|
||||
// ARC mode (promote via a no-op split)
|
||||
for at in [0, 5, 11] {
|
||||
let mut buf = BytesMut::with_capacity(64);
|
||||
buf.extend_from_slice(b"hello world");
|
||||
let _ = buf.split_to(0); // promotes to ARC
|
||||
|
||||
let other = buf.split_off(at);
|
||||
assert_eq!(
|
||||
buf.capacity() + other.capacity(),
|
||||
64,
|
||||
"ARC split_off at {} should preserve total capacity",
|
||||
at
|
||||
);
|
||||
}
|
||||
|
||||
for at in [0, 5, 11] {
|
||||
let mut buf = BytesMut::with_capacity(64);
|
||||
buf.extend_from_slice(b"hello world");
|
||||
let _ = buf.split_to(0); // promotes to ARC
|
||||
|
||||
let other = buf.split_to(at);
|
||||
assert_eq!(
|
||||
buf.capacity() + other.capacity(),
|
||||
64,
|
||||
"ARC split_to at {} should preserve total capacity",
|
||||
at
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct SharedAtomicCounter(Arc<AtomicUsize>);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user