Skip to content

Commit 69c4728

Browse files
committed
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.
1 parent 088216f commit 69c4728

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/liballoc/slice.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,25 @@ impl<T> [T] {
671671
/// # Examples
672672
///
673673
/// ```
674-
/// let v = [10, 40, 30, 20, 50];
675-
/// let (v1, v2) = v.split_at(2);
676-
/// assert_eq!([10, 40], v1);
677-
/// assert_eq!([30, 20, 50], v2);
674+
/// let v = [1, 2, 3, 4, 5, 6];
675+
///
676+
/// {
677+
/// let (left, right) = v.split_at(0);
678+
/// assert!(left == []);
679+
/// assert!(right == [1, 2, 3, 4, 5, 6]);
680+
/// }
681+
///
682+
/// {
683+
/// let (left, right) = v.split_at(2);
684+
/// assert!(left == [1, 2]);
685+
/// assert!(right == [3, 4, 5, 6]);
686+
/// }
687+
///
688+
/// {
689+
/// let (left, right) = v.split_at(6);
690+
/// assert!(left == [1, 2, 3, 4, 5, 6]);
691+
/// assert!(right == []);
692+
/// }
678693
/// ```
679694
#[stable(feature = "rust1", since = "1.0.0")]
680695
#[inline]
@@ -695,26 +710,16 @@ impl<T> [T] {
695710
/// # Examples
696711
///
697712
/// ```
698-
/// let mut v = [1, 2, 3, 4, 5, 6];
699-
///
713+
/// let mut v = [1, 0, 3, 0, 5, 6];
700714
/// // scoped to restrict the lifetime of the borrows
701715
/// {
702-
/// let (left, right) = v.split_at_mut(0);
703-
/// assert!(left == []);
704-
/// assert!(right == [1, 2, 3, 4, 5, 6]);
705-
/// }
706-
///
707-
/// {
708716
/// let (left, right) = v.split_at_mut(2);
709-
/// assert!(left == [1, 2]);
710-
/// assert!(right == [3, 4, 5, 6]);
711-
/// }
712-
///
713-
/// {
714-
/// let (left, right) = v.split_at_mut(6);
715-
/// assert!(left == [1, 2, 3, 4, 5, 6]);
716-
/// assert!(right == []);
717+
/// assert!(left == [1, 0]);
718+
/// assert!(right == [3, 0, 5, 6]);
719+
/// left[1] = 2;
720+
/// right[1] = 4;
717721
/// }
722+
/// assert!(v == [1, 2, 3, 4, 5, 6]);
718723
/// ```
719724
#[stable(feature = "rust1", since = "1.0.0")]
720725
#[inline]

0 commit comments

Comments
 (0)