diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2017-01-19 11:56:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-19 11:56:12 +0100 |
| commit | 3946079d3793eb3324d650d8bdc7e826bdbe2689 (patch) | |
| tree | ff736fc78a6f5abd28bedd30820a8a1eb689824a | |
| parent | 87482ee03ad8ffe9df4f593562ff3e71b8344cb7 (diff) | |
| parent | c8822da79b963b8180b05cd1886d801230e52d05 (diff) | |
| download | rust-3946079d3793eb3324d650d8bdc7e826bdbe2689.tar.gz rust-3946079d3793eb3324d650d8bdc7e826bdbe2689.zip | |
Rollup merge of #39165 - frewsxcv:slice, r=GuillaumeGomez
A few improvements to the slice docs.
* Simplify `Option::iter_mut` doc example.
* Document 'empty' corner-cases for `slice::{starts_with, ends_with}`.
* Indicate 'true' as code-like.
| -rw-r--r-- | src/libcollections/slice.rs | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index d25799800b7..e704f400d49 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -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 /// @@ -549,12 +549,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]); /// ``` @@ -889,7 +885,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 /// @@ -905,7 +901,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 /// @@ -916,6 +912,15 @@ 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 @@ -923,7 +928,7 @@ impl<T> [T] { 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 /// @@ -934,6 +939,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 |
