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

A few improvements to the slice docs. #39165

Merged
merged 1 commit into from
Jan 19, 2017
Merged
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
34 changes: 24 additions & 10 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<T> [T] {
core_slice::SliceExt::len(self)
}

/// Returns true if the slice has a length of 0.
/// Returns `true` if the slice has a length of 0.
///
/// # Example
///
Expand Down Expand Up @@ -540,12 +540,8 @@ impl<T> [T] {
///
/// ```
/// let x = &mut [1, 2, 4];
/// {
/// let iterator = x.iter_mut();
///
/// for elem in iterator {
/// *elem += 2;
/// }
/// for elem in x.iter_mut() {
/// *elem += 2;
/// }
/// assert_eq!(x, &[3, 4, 6]);
/// ```
Expand Down Expand Up @@ -880,7 +876,7 @@ impl<T> [T] {
core_slice::SliceExt::rsplitn_mut(self, n, pred)
}

/// Returns true if the slice contains an element with the given value.
/// Returns `true` if the slice contains an element with the given value.
///
/// # Examples
///
Expand All @@ -896,7 +892,7 @@ impl<T> [T] {
core_slice::SliceExt::contains(self, x)
}

/// Returns true if `needle` is a prefix of the slice.
/// Returns `true` if `needle` is a prefix of the slice.
///
/// # Examples
///
Expand All @@ -907,14 +903,23 @@ impl<T> [T] {
/// assert!(!v.starts_with(&[50]));
/// assert!(!v.starts_with(&[10, 50]));
/// ```
///
/// Always returns `true` if `needle` is an empty slice:
///
/// ```
/// let v = &[10, 40, 30];
/// assert!(v.starts_with(&[]));
/// let v: &[u8] = &[];
/// assert!(v.starts_with(&[]));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn starts_with(&self, needle: &[T]) -> bool
where T: PartialEq
{
core_slice::SliceExt::starts_with(self, needle)
}

/// Returns true if `needle` is a suffix of the slice.
/// Returns `true` if `needle` is a suffix of the slice.
///
/// # Examples
///
Expand All @@ -925,6 +930,15 @@ impl<T> [T] {
/// assert!(!v.ends_with(&[50]));
/// assert!(!v.ends_with(&[50, 30]));
/// ```
///
/// Always returns `true` if `needle` is an empty slice:
///
/// ```
/// let v = &[10, 40, 30];
/// assert!(v.ends_with(&[]));
/// let v: &[u8] = &[];
/// assert!(v.ends_with(&[]));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn ends_with(&self, needle: &[T]) -> bool
where T: PartialEq
Expand Down