@@ -92,14 +92,20 @@ impl<'data> BorrowedBuf<'data> {
92
92
#[ inline]
93
93
pub fn filled ( & self ) -> & [ u8 ] {
94
94
// SAFETY: We only slice the filled part of the buffer, which is always valid
95
- unsafe { MaybeUninit :: slice_assume_init_ref ( & self . buf [ 0 ..self . filled ] ) }
95
+ unsafe {
96
+ let buf = self . buf . get_unchecked ( ..self . filled ) ;
97
+ MaybeUninit :: slice_assume_init_ref ( buf)
98
+ }
96
99
}
97
100
98
101
/// Returns a mutable reference to the filled portion of the buffer.
99
102
#[ inline]
100
103
pub fn filled_mut ( & mut self ) -> & mut [ u8 ] {
101
104
// SAFETY: We only slice the filled part of the buffer, which is always valid
102
- unsafe { MaybeUninit :: slice_assume_init_mut ( & mut self . buf [ 0 ..self . filled ] ) }
105
+ unsafe {
106
+ let buf = self . buf . get_unchecked_mut ( ..self . filled ) ;
107
+ MaybeUninit :: slice_assume_init_mut ( buf)
108
+ }
103
109
}
104
110
105
111
/// Returns a cursor over the unfilled part of the buffer.
@@ -205,15 +211,19 @@ impl<'a> BorrowedCursor<'a> {
205
211
#[ inline]
206
212
pub fn init_ref ( & self ) -> & [ u8 ] {
207
213
// SAFETY: We only slice the initialized part of the buffer, which is always valid
208
- unsafe { MaybeUninit :: slice_assume_init_ref ( & self . buf . buf [ self . buf . filled ..self . buf . init ] ) }
214
+ unsafe {
215
+ let buf = self . buf . buf . get_unchecked ( self . buf . filled ..self . buf . init ) ;
216
+ MaybeUninit :: slice_assume_init_ref ( buf)
217
+ }
209
218
}
210
219
211
220
/// Returns a mutable reference to the initialized portion of the cursor.
212
221
#[ inline]
213
222
pub fn init_mut ( & mut self ) -> & mut [ u8 ] {
214
223
// SAFETY: We only slice the initialized part of the buffer, which is always valid
215
224
unsafe {
216
- MaybeUninit :: slice_assume_init_mut ( & mut self . buf . buf [ self . buf . filled ..self . buf . init ] )
225
+ let buf = self . buf . buf . get_unchecked_mut ( self . buf . filled ..self . buf . init ) ;
226
+ MaybeUninit :: slice_assume_init_mut ( buf)
217
227
}
218
228
}
219
229
@@ -222,7 +232,8 @@ impl<'a> BorrowedCursor<'a> {
222
232
/// It is safe to uninitialize any of these bytes.
223
233
#[ inline]
224
234
pub fn uninit_mut ( & mut self ) -> & mut [ MaybeUninit < u8 > ] {
225
- & mut self . buf . buf [ self . buf . init ..]
235
+ // SAFETY: always in bounds
236
+ unsafe { self . buf . buf . get_unchecked_mut ( self . buf . init ..) }
226
237
}
227
238
228
239
/// Returns a mutable reference to the whole cursor.
@@ -232,7 +243,8 @@ impl<'a> BorrowedCursor<'a> {
232
243
/// The caller must not uninitialize any bytes in the initialized portion of the cursor.
233
244
#[ inline]
234
245
pub unsafe fn as_mut ( & mut self ) -> & mut [ MaybeUninit < u8 > ] {
235
- & mut self . buf . buf [ self . buf . filled ..]
246
+ // SAFETY: always in bounds
247
+ unsafe { self . buf . buf . get_unchecked_mut ( self . buf . filled ..) }
236
248
}
237
249
238
250
/// Advance the cursor by asserting that `n` bytes have been filled.
0 commit comments