File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -223,9 +223,15 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
223
223
unsafe { from_raw_parts ( range. start , range. end . sub_ptr ( range. start ) ) }
224
224
}
225
225
226
- /// Performs the same functionality as [`from_ptr_range`], except that a
226
+ /// Forms a mutable slice from a pointer range.
227
+ ///
228
+ /// This is the same functionality as [`from_ptr_range`], except that a
227
229
/// mutable slice is returned.
228
230
///
231
+ /// This function is useful for interacting with foreign interfaces which
232
+ /// use two pointers to refer to a range of elements in memory, as is
233
+ /// common in C++.
234
+ ///
229
235
/// # Safety
230
236
///
231
237
/// Behavior is undefined if any of the following conditions are violated:
@@ -255,6 +261,14 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
255
261
///
256
262
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
257
263
///
264
+ /// # Caveat
265
+ ///
266
+ /// The lifetime for the returned slice is inferred from its usage. To
267
+ /// prevent accidental misuse, it's suggested to tie the lifetime to whichever
268
+ /// source lifetime is safe in the context, such as by providing a helper
269
+ /// function taking the lifetime of a host value for the slice, or by explicit
270
+ /// annotation.
271
+ ///
258
272
/// # Examples
259
273
///
260
274
/// ```
You can’t perform that action at this time.
0 commit comments