diff --git a/src/common/rewind.rs b/src/common/rewind.rs index e2fc5bf2..760d7966 100644 --- a/src/common/rewind.rs +++ b/src/common/rewind.rs @@ -37,9 +37,8 @@ where if let Some(mut prefix) = self.pre.take() { // If there are no remaining bytes, let the bytes get dropped. if !prefix.is_empty() { - let copy_len = cmp::min(prefix.len(), remaining(&mut buf)); - // TODO: There should be a way to do following two lines cleaner... - put_slice(&mut buf, &prefix[..copy_len]); + let copy_len = cmp::min(prefix.len(), buf.remaining()); + buf.put_slice(&prefix[..copy_len]); prefix.advance(copy_len); // Put back what's left if !prefix.is_empty() { @@ -53,33 +52,6 @@ where } } -fn remaining(cursor: &mut ReadBufCursor<'_>) -> usize { - // SAFETY: - // We do not uninitialize any set bytes. - unsafe { cursor.as_mut().len() } -} - -// Copied from `ReadBufCursor::put_slice`. -// If that becomes public, we could ditch this. -fn put_slice(cursor: &mut ReadBufCursor<'_>, slice: &[u8]) { - assert!( - remaining(cursor) >= slice.len(), - "buf.len() must fit in remaining()" - ); - - let amt = slice.len(); - - // SAFETY: - // the length is asserted above - unsafe { - cursor.as_mut()[..amt] - .as_mut_ptr() - .cast::() - .copy_from_nonoverlapping(slice.as_ptr(), amt); - cursor.advance(amt); - } -} - impl Write for Rewind where T: Write + Unpin,