@@ -195,19 +195,31 @@ impl Buf {
195
195
self . as_slice ( ) . into_rc ( )
196
196
}
197
197
198
- /// Provides plumbing to core `Vec::truncate`.
199
- /// More well behaving alternative to allowing outer types
200
- /// full mutable access to the core `Vec`.
201
- #[ inline]
202
- pub ( crate ) fn truncate ( & mut self , len : usize ) {
198
+ /// Provides plumbing to `Vec::truncate` without giving full mutable access
199
+ /// to the `Vec`.
200
+ ///
201
+ /// # Safety
202
+ ///
203
+ /// The length must be at an `OsStr` boundary, according to
204
+ /// `Slice::check_public_boundary`.
205
+ #[ inline]
206
+ pub unsafe fn truncate_unchecked ( & mut self , len : usize ) {
203
207
self . inner . truncate ( len) ;
204
208
}
205
209
206
- /// Provides plumbing to core `Vec::extend_from_slice`.
207
- /// More well behaving alternative to allowing outer types
208
- /// full mutable access to the core `Vec`.
210
+ /// Provides plumbing to `Vec::extend_from_slice` without giving full
211
+ /// mutable access to the `Vec`.
212
+ ///
213
+ /// # Safety
214
+ ///
215
+ /// The slice must be valid for the platform encoding (as described in
216
+ /// [`Slice::from_encoded_bytes_unchecked`]).
217
+ ///
218
+ /// This bypasses the WTF-8 surrogate joining, so `self` must not end with a
219
+ /// leading surrogate half and `other` must not start with with a trailing
220
+ /// surrogate half.
209
221
#[ inline]
210
- pub ( crate ) fn extend_from_slice ( & mut self , other : & [ u8 ] ) {
222
+ pub unsafe fn extend_from_slice_unchecked ( & mut self , other : & [ u8 ] ) {
211
223
self . inner . extend_from_slice ( other) ;
212
224
}
213
225
}
0 commit comments