Skip to content

Commit 49cd331

Browse files
authored
Rollup merge of #160595 - AbeZbm:clarify_str_split_doc, r=clarfonthey
Clarify `str::split_at` docs Fixes #158990 The documentation currently describes the split position as an "index", which can be confusing because `mid` is a byte offset rather than an element index. This change clarifies the relationship between `mid` and the returned slices by describing the length of the first slice. The first returned slice contains exactly `mid` bytes from the start of the string slice, and the second slice contains the remaining bytes.
2 parents f4870fd + d9e5ec7 commit 49cd331

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

library/core/src/str/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -824,13 +824,13 @@ impl str {
824824
unsafe { &mut *(begin..end).get_unchecked_mut(self) }
825825
}
826826

827-
/// Divides one string slice into two at an index.
827+
/// Divides one string slice into two at a byte offset.
828828
///
829829
/// The argument, `mid`, should be a byte offset from the start of the
830830
/// string. It must also be on the boundary of a UTF-8 code point.
831831
///
832-
/// The two slices returned go from the start of the string slice to `mid`,
833-
/// and from `mid` to the end of the string slice.
832+
/// The first returned slice contains exactly the first `mid` bytes, and the
833+
/// second contains all remaining bytes.
834834
///
835835
/// To get mutable string slices instead, see the [`split_at_mut`]
836836
/// method.
@@ -864,13 +864,13 @@ impl str {
864864
}
865865
}
866866

867-
/// Divides one mutable string slice into two at an index.
867+
/// Divides one mutable string slice into two at a byte offset.
868868
///
869869
/// The argument, `mid`, should be a byte offset from the start of the
870870
/// string. It must also be on the boundary of a UTF-8 code point.
871871
///
872-
/// The two slices returned go from the start of the string slice to `mid`,
873-
/// and from `mid` to the end of the string slice.
872+
/// The first returned slice contains exactly the first `mid` bytes, and the
873+
/// second contains all remaining bytes.
874874
///
875875
/// To get immutable string slices instead, see the [`split_at`] method.
876876
///
@@ -908,14 +908,14 @@ impl str {
908908
}
909909
}
910910

911-
/// Divides one string slice into two at an index.
911+
/// Divides one string slice into two at a byte offset.
912912
///
913913
/// The argument, `mid`, should be a valid byte offset from the start of the
914914
/// string. It must also be on the boundary of a UTF-8 code point. The
915915
/// method returns `None` if that’s not the case.
916916
///
917-
/// The two slices returned go from the start of the string slice to `mid`,
918-
/// and from `mid` to the end of the string slice.
917+
/// The first returned slice contains exactly the first `mid` bytes, and the
918+
/// second contains all remaining bytes.
919919
///
920920
/// To get mutable string slices instead, see the [`split_at_mut_checked`]
921921
/// method.
@@ -948,14 +948,14 @@ impl str {
948948
}
949949
}
950950

951-
/// Divides one mutable string slice into two at an index.
951+
/// Divides one mutable string slice into two at a byte offset.
952952
///
953953
/// The argument, `mid`, should be a valid byte offset from the start of the
954954
/// string. It must also be on the boundary of a UTF-8 code point. The
955955
/// method returns `None` if that’s not the case.
956956
///
957-
/// The two slices returned go from the start of the string slice to `mid`,
958-
/// and from `mid` to the end of the string slice.
957+
/// The first returned slice contains exactly the first `mid` bytes, and the
958+
/// second contains all remaining bytes.
959959
///
960960
/// To get immutable string slices instead, see the [`split_at_checked`] method.
961961
///
@@ -989,7 +989,7 @@ impl str {
989989
}
990990
}
991991

992-
/// Divides one string slice into two at an index.
992+
/// Divides one string slice into two at a byte offset.
993993
///
994994
/// # Safety
995995
///
@@ -1008,7 +1008,7 @@ impl str {
10081008
}
10091009
}
10101010

1011-
/// Divides one string slice into two at an index.
1011+
/// Divides one mutable string slice into two at a byte offset.
10121012
///
10131013
/// # Safety
10141014
///

0 commit comments

Comments
 (0)