Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation for slice strip_* functions #75078

Merged
merged 5 commits into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1703,8 +1703,10 @@ impl<T> [T] {

/// Returns a subslice with the prefix removed.
///
/// This method returns [`None`] if slice does not start with `prefix`.
/// Also it returns the original slice if `prefix` is an empty slice.
/// If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`.
/// If `prefix` is empty, simply returns the original slice.
///
/// If the slice does not start with `prefix`, returns `None`.
///
/// # Examples
///
Expand Down Expand Up @@ -1734,8 +1736,10 @@ impl<T> [T] {

/// Returns a subslice with the suffix removed.
///
/// This method returns [`None`] if slice does not end with `suffix`.
/// Also it returns the original slice if `suffix` is an empty slice
/// If the slice ends with `suffix`, returns the subslice before the suffix, wrapped in `Some`.
/// If `suffix` is empty, simply returns the original slice.
///
/// If the slice does not end with `suffix`, returns `None`.
///
/// # Examples
///
Expand Down
14 changes: 6 additions & 8 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1964,11 +1964,10 @@ impl str {

/// Returns a string slice with the prefix removed.
///
/// If the string starts with the pattern `prefix`, `Some` is returned with the substring where
/// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly
/// once.
/// If the string starts with the pattern `prefix`, returns substring after the prefix, wrapped
/// in `Some`. Unlike `trim_start_matches`, this method removes the prefix exactly once.
///
/// If the string does not start with `prefix`, `None` is returned.
/// If the string does not start with `prefix`, returns `None`.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
Expand All @@ -1992,11 +1991,10 @@ impl str {

/// Returns a string slice with the suffix removed.
///
/// If the string ends with the pattern `suffix`, `Some` is returned with the substring where
/// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly
/// once.
/// If the string ends with the pattern `suffix`, returns the substring before the suffix,
/// wrapped in `Some`. Unlike `trim_end_matches`, this method removes the suffix exactly once.
///
/// If the string does not end with `suffix`, `None` is returned.
/// If the string does not end with `suffix`, returns `None`.
///
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
/// function or closure that determines if a character matches.
Expand Down