mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-07 00:00:13 +02:00
Truncate tweaks (#694)
This commit is contained in:
+2
-1
@@ -422,8 +422,9 @@ impl BytesMut {
|
||||
/// assert_eq!(buf, b"hello"[..]);
|
||||
/// ```
|
||||
pub fn truncate(&mut self, len: usize) {
|
||||
if len <= self.len() {
|
||||
if len < self.len() {
|
||||
unsafe {
|
||||
// SAFETY: Shrinking the buffer cannot expose uninitialized bytes.
|
||||
self.set_len(len);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user