From 69c472897fb74ba98584c9b33f60ca6f04b04afe Mon Sep 17 00:00:00 2001 From: Niels Egberts Date: Mon, 4 Sep 2017 22:59:34 +0100 Subject: [PATCH] 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. --- src/liballoc/slice.rs | 45 ++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 7787ace944119..2045d5ddd972d 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -671,10 +671,25 @@ impl [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] { /// # 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]