Skip to content

Commit 5631c01

Browse files
committed
core: make BorrowedCursor::ensure_init return &[u8]
1 parent ed0006a commit 5631c01

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,9 @@ impl<'a> BorrowedCursor<'a> {
297297
self
298298
}
299299

300-
/// Initializes all bytes in the cursor.
300+
/// Initializes all bytes in the cursor and returns them.
301301
#[inline]
302-
pub fn ensure_init(&mut self) -> &mut Self {
302+
pub fn ensure_init(&mut self) -> &mut [u8] {
303303
// SAFETY: always in bounds and we never uninitialize these bytes.
304304
let uninit = unsafe { self.buf.buf.get_unchecked_mut(self.buf.init..) };
305305

@@ -310,7 +310,7 @@ impl<'a> BorrowedCursor<'a> {
310310
}
311311
self.buf.init = self.buf.capacity();
312312

313-
self
313+
self.init_mut()
314314
}
315315

316316
/// Asserts that the first `n` unfilled bytes of the cursor are initialized.

library/std/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ pub(crate) fn default_read_buf<F>(read: F, mut cursor: BorrowedCursor<'_>) -> Re
587587
where
588588
F: FnOnce(&mut [u8]) -> Result<usize>,
589589
{
590-
let n = read(cursor.ensure_init().init_mut())?;
590+
let n = read(cursor.ensure_init())?;
591591
cursor.advance(n);
592592
Ok(())
593593
}

0 commit comments

Comments
 (0)