Skip to content

Commit

Permalink
Rollup merge of rust-lang#44325 - nielsegberts:master, r=steveklabnik
Browse files Browse the repository at this point in the history
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.

See rust-lang#44314

r? @steveklabnik
  • Loading branch information
Mark-Simulacrum authored Sep 6, 2017
2 parents bc52d58 + 69c4728 commit 68e8c40
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 68e8c40

Please sign in to comment.