Skip to content

Commit c3f57a8

Browse files
committed
Add non mut spare_capacity().
1 parent 4b53a29 commit c3f57a8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/bytes_mut.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,17 @@ impl BytesMut {
11171117
slice::from_raw_parts_mut(ptr.cast(), len)
11181118
}
11191119
}
1120+
1121+
/// Returns the remaining spare capacity of the buffer.
1122+
#[inline]
1123+
pub fn spare_capacity(&self) -> &[MaybeUninit<u8>] {
1124+
unsafe {
1125+
let ptr = self.ptr.as_ptr().add(self.len);
1126+
let len = self.cap - self.len;
1127+
1128+
slice::from_raw_parts(ptr.cast(), len)
1129+
}
1130+
}
11201131
}
11211132

11221133
impl Drop for BytesMut {

0 commit comments

Comments
 (0)