diff options
author | 2022-06-11 07:12:53 +0300 | |
---|---|---|
committer | 2022-06-11 13:12:53 +0900 | |
commit | 3536017ccfc5cf2d837a5cee8262b1de6c3eafc7 (patch) | |
tree | db243a7ca000243f7a64af53370464ad996a54a4 /src | |
parent | b8d27c016f53f0c1fea920223bc5a92f329d47df (diff) | |
download | bytes-3536017ccfc5cf2d837a5cee8262b1de6c3eafc7.tar.gz bytes-3536017ccfc5cf2d837a5cee8262b1de6c3eafc7.tar.zst bytes-3536017ccfc5cf2d837a5cee8262b1de6c3eafc7.zip |
Fix chain remaining_mut(), allowing to chain growing buffer (#488)
Diffstat (limited to 'src')
-rw-r--r-- | src/buf/buf_mut.rs | 4 | ||||
-rw-r--r-- | src/buf/chain.rs | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index 4c2bd2c..7f67f7b 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -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 diff --git a/src/buf/chain.rs b/src/buf/chain.rs index 9ce5f23..78979a1 100644 --- a/src/buf/chain.rs +++ b/src/buf/chain.rs @@ -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 { |