Skip to content

Commit 2cd5faf

Browse files
committed
Sync docs of slice::{from_ptr_range, from_ptr_range_mut}
1 parent bc1216e commit 2cd5faf

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

library/core/src/slice/raw.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,15 @@ pub const unsafe fn from_ptr_range<'a, T>(range: Range<*const T>) -> &'a [T] {
223223
unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
224224
}
225225

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
227229
/// mutable slice is returned.
228230
///
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+
///
229235
/// # Safety
230236
///
231237
/// 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] {
255261
///
256262
/// This function panics if `T` is a Zero-Sized Type (“ZST”).
257263
///
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+
///
258272
/// # Examples
259273
///
260274
/// ```

0 commit comments

Comments
 (0)