@@ -149,7 +149,6 @@ impl<'data> BorrowedBuf<'data> {
149
149
#[ inline]
150
150
pub fn unfilled < ' this > ( & ' this mut self ) -> BorrowedCursor < ' this > {
151
151
BorrowedCursor {
152
- start : self . filled ,
153
152
// SAFETY: we never assign into `BorrowedCursor::buf`, so treating its
154
153
// lifetime covariantly is safe.
155
154
buf : unsafe {
@@ -205,9 +204,6 @@ pub struct BorrowedCursor<'a> {
205
204
// we create a `BorrowedCursor`. This is only safe if we never replace `buf` by assigning into
206
205
// it, so don't do that!
207
206
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 ,
211
207
}
212
208
213
209
impl < ' a > BorrowedCursor < ' a > {
@@ -225,7 +221,6 @@ impl<'a> BorrowedCursor<'a> {
225
221
self . buf ,
226
222
)
227
223
} ,
228
- start : self . start ,
229
224
}
230
225
}
231
226
@@ -235,23 +230,12 @@ impl<'a> BorrowedCursor<'a> {
235
230
self . buf . capacity ( ) - self . buf . filled
236
231
}
237
232
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.
239
234
///
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.
242
236
#[ inline]
243
237
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
255
239
}
256
240
257
241
/// Returns a mutable reference to the initialized portion of the cursor.
@@ -264,15 +248,6 @@ impl<'a> BorrowedCursor<'a> {
264
248
}
265
249
}
266
250
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
-
276
251
/// Returns a mutable reference to the whole cursor.
277
252
///
278
253
/// # Safety
@@ -325,7 +300,9 @@ impl<'a> BorrowedCursor<'a> {
325
300
/// Initializes all bytes in the cursor.
326
301
#[ inline]
327
302
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
+
329
306
// SAFETY: 0 is a valid value for MaybeUninit<u8> and the length matches the allocation
330
307
// since it is comes from a slice reference.
331
308
unsafe {
0 commit comments