mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #44325 - nielsegberts:master, r=steveklabnik
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 #44314 r? @steveklabnik
This commit is contained in:
commit
a4b54848d4
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user