diff options
| author | Benoît du Garreau <benoit@dugarreau.fr> | 2025-07-09 18:11:26 +0200 |
|---|---|---|
| committer | Benoît du Garreau <benoit@dugarreau.fr> | 2025-07-09 18:11:26 +0200 |
| commit | 803b4d262241b22a4dfe75fcec49eaf920e0816b (patch) | |
| tree | f7a993502d363fc242fd357735cdcf7b949c7622 /library | |
| parent | 6b3ae3f6e45a33c2d95fa0362c9b2593e567fd34 (diff) | |
| download | rust-803b4d262241b22a4dfe75fcec49eaf920e0816b.tar.gz rust-803b4d262241b22a4dfe75fcec49eaf920e0816b.zip | |
core: Remove `BorrowedCursor::init_ref` method
This method was not really useful: at no point one would only need to read the initialized part of the cursor without mutating it.
Diffstat (limited to 'library')
| -rw-r--r-- | library/core/src/io/borrowed_buf.rs | 10 | ||||
| -rw-r--r-- | library/coretests/tests/io/borrowed_buf.rs | 4 | ||||
| -rw-r--r-- | library/std/src/io/mod.rs | 6 |
3 files changed, 4 insertions, 16 deletions
diff --git a/library/core/src/io/borrowed_buf.rs b/library/core/src/io/borrowed_buf.rs index 854e03cf182..11ace041998 100644 --- a/library/core/src/io/borrowed_buf.rs +++ b/library/core/src/io/borrowed_buf.rs @@ -227,16 +227,6 @@ impl<'a> BorrowedCursor<'a> { self.buf.filled - self.start } - /// Returns a shared reference to the initialized portion of the cursor. - #[inline] - pub fn init_ref(&self) -> &[u8] { - // SAFETY: We only slice the initialized part of the buffer, which is always valid - unsafe { - let buf = self.buf.buf.get_unchecked(self.buf.filled..self.buf.init); - buf.assume_init_ref() - } - } - /// Returns a mutable reference to the initialized portion of the cursor. #[inline] pub fn init_mut(&mut self) -> &mut [u8] { diff --git a/library/coretests/tests/io/borrowed_buf.rs b/library/coretests/tests/io/borrowed_buf.rs index fbd3864dcac..fe0e26f3e9d 100644 --- a/library/coretests/tests/io/borrowed_buf.rs +++ b/library/coretests/tests/io/borrowed_buf.rs @@ -61,7 +61,7 @@ fn clear() { assert_eq!(rbuf.filled().len(), 0); assert_eq!(rbuf.unfilled().capacity(), 16); - assert_eq!(rbuf.unfilled().init_ref(), [255; 16]); + assert_eq!(rbuf.unfilled().init_mut(), [255; 16]); } #[test] @@ -142,7 +142,6 @@ fn cursor_set_init() { } assert_eq!(rbuf.init_len(), 8); - assert_eq!(rbuf.unfilled().init_ref().len(), 8); assert_eq!(rbuf.unfilled().init_mut().len(), 8); assert_eq!(rbuf.unfilled().uninit_mut().len(), 8); assert_eq!(unsafe { rbuf.unfilled().as_mut().len() }, 16); @@ -160,7 +159,6 @@ fn cursor_set_init() { } assert_eq!(rbuf.init_len(), 12); - assert_eq!(rbuf.unfilled().init_ref().len(), 8); assert_eq!(rbuf.unfilled().init_mut().len(), 8); assert_eq!(rbuf.unfilled().uninit_mut().len(), 4); assert_eq!(unsafe { rbuf.unfilled().as_mut().len() }, 12); diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 17c32d7a571..d351ee5e739 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -489,7 +489,7 @@ pub(crate) fn default_read_to_end<R: Read + ?Sized>( } }; - let unfilled_but_initialized = cursor.init_ref().len(); + let unfilled_but_initialized = cursor.init_mut().len(); let bytes_read = cursor.written(); let was_fully_initialized = read_buf.init_len() == buf_len; @@ -3053,7 +3053,7 @@ impl<T: Read> Read for Take<T> { // The condition above guarantees that `self.limit` fits in `usize`. let limit = self.limit as usize; - let extra_init = cmp::min(limit, buf.init_ref().len()); + let extra_init = cmp::min(limit, buf.init_mut().len()); // SAFETY: no uninit data is written to ibuf let ibuf = unsafe { &mut buf.as_mut()[..limit] }; @@ -3068,7 +3068,7 @@ impl<T: Read> Read for Take<T> { let mut cursor = sliced_buf.unfilled(); let result = self.inner.read_buf(cursor.reborrow()); - let new_init = cursor.init_ref().len(); + let new_init = cursor.init_mut().len(); let filled = sliced_buf.len(); // cursor / sliced_buf / ibuf must drop here |
