Skip to content

Commit 64dc70a

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

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/bytes_mut.rs

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

11221132
impl Drop for BytesMut {

0 commit comments

Comments
 (0)