Skip to content

Commit 2168210

Browse files
Rollup merge of #75078 - ijackson:slice-strip, r=steveklabnik
Improve documentation for slice strip_* functions Prompted by the stabilisation tracking issue #73413 I looked at the docs for `strip_prefix` and `strip_suffix` for both `str` and `slice`, and I felt they could be slightly improved. Thanks for your attention.
2 parents a53fb30 + 22358c6 commit 2168210

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

library/core/src/slice/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1768,8 +1768,10 @@ impl<T> [T] {
17681768

17691769
/// Returns a subslice with the prefix removed.
17701770
///
1771-
/// This method returns [`None`] if slice does not start with `prefix`.
1772-
/// Also it returns the original slice if `prefix` is an empty slice.
1771+
/// If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`.
1772+
/// If `prefix` is empty, simply returns the original slice.
1773+
///
1774+
/// If the slice does not start with `prefix`, returns `None`.
17731775
///
17741776
/// # Examples
17751777
///
@@ -1799,8 +1801,10 @@ impl<T> [T] {
17991801

18001802
/// Returns a subslice with the suffix removed.
18011803
///
1802-
/// This method returns [`None`] if slice does not end with `suffix`.
1803-
/// Also it returns the original slice if `suffix` is an empty slice
1804+
/// If the slice ends with `suffix`, returns the subslice before the suffix, wrapped in `Some`.
1805+
/// If `suffix` is empty, simply returns the original slice.
1806+
///
1807+
/// If the slice does not end with `suffix`, returns `None`.
18041808
///
18051809
/// # Examples
18061810
///

library/core/src/str/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1965,11 +1965,10 @@ impl str {
19651965

19661966
/// Returns a string slice with the prefix removed.
19671967
///
1968-
/// If the string starts with the pattern `prefix`, `Some` is returned with the substring where
1969-
/// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly
1970-
/// once.
1968+
/// If the string starts with the pattern `prefix`, returns substring after the prefix, wrapped
1969+
/// in `Some`. Unlike `trim_start_matches`, this method removes the prefix exactly once.
19711970
///
1972-
/// If the string does not start with `prefix`, `None` is returned.
1971+
/// If the string does not start with `prefix`, returns `None`.
19731972
///
19741973
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
19751974
/// function or closure that determines if a character matches.
@@ -1993,11 +1992,10 @@ impl str {
19931992

19941993
/// Returns a string slice with the suffix removed.
19951994
///
1996-
/// If the string ends with the pattern `suffix`, `Some` is returned with the substring where
1997-
/// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly
1998-
/// once.
1995+
/// If the string ends with the pattern `suffix`, returns the substring before the suffix,
1996+
/// wrapped in `Some`. Unlike `trim_end_matches`, this method removes the suffix exactly once.
19991997
///
2000-
/// If the string does not end with `suffix`, `None` is returned.
1998+
/// If the string does not end with `suffix`, returns `None`.
20011999
///
20022000
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
20032001
/// function or closure that determines if a character matches.

0 commit comments

Comments
 (0)