Fix chain remaining_mut(), allowing to chain growing buffer (#488)

This commit is contained in:
Zettroke
2022-06-11 13:12:53 +09:00
committed by GitHub
parent b8d27c016f
commit 3536017ccf
3 changed files with 27 additions and 2 deletions
+4
View File
@@ -56,6 +56,10 @@ pub unsafe trait BufMut {
/// Implementations of `remaining_mut` should ensure that the return value
/// does not change unless a call is made to `advance_mut` or any other
/// function that is documented to change the `BufMut`'s current position.
///
/// # Note
///
/// `remaining_mut` may return value smaller than actual available space.
fn remaining_mut(&self) -> usize;
/// Advance the internal cursor of the BufMut
+1 -2
View File
@@ -198,8 +198,7 @@ where
fn remaining_mut(&self) -> usize {
self.a
.remaining_mut()
.checked_add(self.b.remaining_mut())
.unwrap()
.saturating_add(self.b.remaining_mut())
}
fn chunk_mut(&mut self) -> &mut UninitSlice {