about summary refs log tree commit diff
path: root/library/core
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2024-12-20 01:36:46 -0500
committerGitHub <noreply@github.com>2024-12-20 01:36:46 -0500
commit1ec6d093b7595073bbaef66fcad8308221ac5dc8 (patch)
tree6e700a92802ffb5c83929d3e8b0c47f2cc4a0ef3 /library/core
parent3cdc3b7e0b516791f4a95eac8a577c37fc75b6ca (diff)
parent3c8bfb7f7bc586afb597155184a14d1a4fe0d244 (diff)
downloadrust-1ec6d093b7595073bbaef66fcad8308221ac5dc8.tar.gz
rust-1ec6d093b7595073bbaef66fcad8308221ac5dc8.zip
Rollup merge of #132830 - wr7:substr_range_documentation, r=tgross35
Rename `elem_offset` to `element_offset`

Tracking issue: #126769

Renames `slice::elem_offset` to `slice::element_offset` and improves the documentation of it and its related methods.

The current documentation can be misinterpreted (as explained [here](https://github.com/rust-lang/rust/issues/126769#issuecomment-2453363897)).
Diffstat (limited to 'library/core')
-rw-r--r--library/core/src/slice/mod.rs15
1 files changed, 8 insertions, 7 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index de00bdf8594..ab65f9d6d2f 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -4641,7 +4641,7 @@ impl<T> [T] {
 
     /// Returns the index that an element reference points to.
     ///
-    /// Returns `None` if `element` does not point within the slice or if it points between elements.
+    /// Returns `None` if `element` does not point to the start of an element within the slice.
     ///
     /// This method is useful for extending slice iterators like [`slice::split`].
     ///
@@ -4661,9 +4661,9 @@ impl<T> [T] {
     /// let num = &nums[2];
     ///
     /// assert_eq!(num, &1);
-    /// assert_eq!(nums.elem_offset(num), Some(2));
+    /// assert_eq!(nums.element_offset(num), Some(2));
     /// ```
-    /// Returning `None` with an in-between element:
+    /// Returning `None` with an unaligned element:
     /// ```
     /// #![feature(substr_range)]
     ///
@@ -4676,12 +4676,12 @@ impl<T> [T] {
     /// assert_eq!(ok_elm, &[0, 1]);
     /// assert_eq!(weird_elm, &[1, 2]);
     ///
-    /// assert_eq!(arr.elem_offset(ok_elm), Some(0)); // Points to element 0
-    /// assert_eq!(arr.elem_offset(weird_elm), None); // Points between element 0 and 1
+    /// assert_eq!(arr.element_offset(ok_elm), Some(0)); // Points to element 0
+    /// assert_eq!(arr.element_offset(weird_elm), None); // Points between element 0 and 1
     /// ```
     #[must_use]
     #[unstable(feature = "substr_range", issue = "126769")]
-    pub fn elem_offset(&self, element: &T) -> Option<usize> {
+    pub fn element_offset(&self, element: &T) -> Option<usize> {
         if T::IS_ZST {
             panic!("elements are zero-sized");
         }
@@ -4702,7 +4702,8 @@ impl<T> [T] {
 
     /// Returns the range of indices that a subslice points to.
     ///
-    /// Returns `None` if `subslice` does not point within the slice or if it points between elements.
+    /// Returns `None` if `subslice` does not point within the slice or if it is not aligned with the
+    /// elements in the slice.
     ///
     /// This method **does not compare elements**. Instead, this method finds the location in the slice that
     /// `subslice` was obtained from. To find the index of a subslice via comparison, instead use