diff options
| author | Niels Egberts <github@nielsegberts.nl> | 2017-09-04 22:59:34 +0100 |
|---|---|---|
| committer | Niels Egberts <github@nielsegberts.nl> | 2017-09-04 22:59:34 +0100 |
| commit | 69c472897fb74ba98584c9b33f60ca6f04b04afe (patch) | |
| tree | 1300ae0e871bd14f70fe1b72485faa6a3da012fa | |
| parent | 088216fb997c9cb12ce049bbe7975d1f657551ca (diff) | |
| download | rust-69c472897fb74ba98584c9b33f60ca6f04b04afe.tar.gz rust-69c472897fb74ba98584c9b33f60ca6f04b04afe.zip | |
Make slice::split_at_mut example demonstrate mutability
Moved the examples from split_at_mut to split_at so the example at split_at_mut can just demonstrate mutability.
| -rw-r--r-- | src/liballoc/slice.rs | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 7787ace9441..2045d5ddd97 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -671,10 +671,25 @@ impl<T> [T] { /// # Examples /// /// ``` - /// let v = [10, 40, 30, 20, 50]; - /// let (v1, v2) = v.split_at(2); - /// assert_eq!([10, 40], v1); - /// assert_eq!([30, 20, 50], v2); + /// let v = [1, 2, 3, 4, 5, 6]; + /// + /// { + /// let (left, right) = v.split_at(0); + /// assert!(left == []); + /// assert!(right == [1, 2, 3, 4, 5, 6]); + /// } + /// + /// { + /// let (left, right) = v.split_at(2); + /// assert!(left == [1, 2]); + /// assert!(right == [3, 4, 5, 6]); + /// } + /// + /// { + /// let (left, right) = v.split_at(6); + /// assert!(left == [1, 2, 3, 4, 5, 6]); + /// assert!(right == []); + /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -695,26 +710,16 @@ impl<T> [T] { /// # Examples /// /// ``` - /// let mut v = [1, 2, 3, 4, 5, 6]; - /// + /// let mut v = [1, 0, 3, 0, 5, 6]; /// // scoped to restrict the lifetime of the borrows /// { - /// let (left, right) = v.split_at_mut(0); - /// assert!(left == []); - /// assert!(right == [1, 2, 3, 4, 5, 6]); - /// } - /// - /// { /// let (left, right) = v.split_at_mut(2); - /// assert!(left == [1, 2]); - /// assert!(right == [3, 4, 5, 6]); - /// } - /// - /// { - /// let (left, right) = v.split_at_mut(6); - /// assert!(left == [1, 2, 3, 4, 5, 6]); - /// assert!(right == []); + /// assert!(left == [1, 0]); + /// assert!(right == [3, 0, 5, 6]); + /// left[1] = 2; + /// right[1] = 4; /// } + /// assert!(v == [1, 2, 3, 4, 5, 6]); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] |
