@@ -149,7 +149,6 @@ impl<'data> BorrowedBuf<'data> {
149149 #[ inline]
150150 pub fn unfilled < ' this > ( & ' this mut self ) -> BorrowedCursor < ' this > {
151151 BorrowedCursor {
152- start : self . filled ,
153152 // SAFETY: we never assign into `BorrowedCursor::buf`, so treating its
154153 // lifetime covariantly is safe.
155154 buf : unsafe {
@@ -205,9 +204,6 @@ pub struct BorrowedCursor<'a> {
205204 // we create a `BorrowedCursor`. This is only safe if we never replace `buf` by assigning into
206205 // it, so don't do that!
207206 buf : & ' a mut BorrowedBuf < ' a > ,
208- /// The length of the filled portion of the underlying buffer at the time of the cursor's
209- /// creation.
210- start : usize ,
211207}
212208
213209impl < ' a > BorrowedCursor < ' a > {
@@ -225,7 +221,6 @@ impl<'a> BorrowedCursor<'a> {
225221 self . buf ,
226222 )
227223 } ,
228- start : self . start ,
229224 }
230225 }
231226
@@ -235,23 +230,12 @@ impl<'a> BorrowedCursor<'a> {
235230 self . buf . capacity ( ) - self . buf . filled
236231 }
237232
238- /// Returns the number of bytes written to this cursor since it was created from a `BorrowedBuf` .
233+ /// Returns the number of bytes written to the `BorrowedBuf` this cursor was created from.
239234 ///
240- /// Note that if this cursor is a reborrowed clone of another, then the count returned is the
241- /// count written via either cursor, not the count since the cursor was reborrowed.
235+ /// In particular, the count returned is shared by all reborrows of the cursor.
242236 #[ inline]
243237 pub fn written ( & self ) -> usize {
244- self . buf . filled - self . start
245- }
246-
247- /// Returns a shared reference to the initialized portion of the cursor.
248- #[ inline]
249- pub fn init_ref ( & self ) -> & [ u8 ] {
250- // SAFETY: We only slice the initialized part of the buffer, which is always valid
251- unsafe {
252- let buf = self . buf . buf . get_unchecked ( self . buf . filled ..self . buf . init ) ;
253- buf. assume_init_ref ( )
254- }
238+ self . buf . filled
255239 }
256240
257241 /// Returns a mutable reference to the initialized portion of the cursor.
@@ -264,15 +248,6 @@ impl<'a> BorrowedCursor<'a> {
264248 }
265249 }
266250
267- /// Returns a mutable reference to the uninitialized part of the cursor.
268- ///
269- /// It is safe to uninitialize any of these bytes.
270- #[ inline]
271- pub fn uninit_mut ( & mut self ) -> & mut [ MaybeUninit < u8 > ] {
272- // SAFETY: always in bounds
273- unsafe { self . buf . buf . get_unchecked_mut ( self . buf . init ..) }
274- }
275-
276251 /// Returns a mutable reference to the whole cursor.
277252 ///
278253 /// # Safety
@@ -325,7 +300,9 @@ impl<'a> BorrowedCursor<'a> {
325300 /// Initializes all bytes in the cursor.
326301 #[ inline]
327302 pub fn ensure_init ( & mut self ) -> & mut Self {
328- let uninit = self . uninit_mut ( ) ;
303+ // SAFETY: always in bounds and we never uninitialize these bytes.
304+ let uninit = unsafe { self . buf . buf . get_unchecked_mut ( self . buf . init ..) } ;
305+
329306 // SAFETY: 0 is a valid value for MaybeUninit<u8> and the length matches the allocation
330307 // since it is comes from a slice reference.
331308 unsafe {
0 commit comments