@@ -10,7 +10,7 @@ use crate::cmp::Ordering::{self, Equal, Greater, Less};
10
10
use crate :: intrinsics:: { exact_div, unchecked_sub} ;
11
11
use crate :: mem:: { self , SizedTypeProperties } ;
12
12
use crate :: num:: NonZero ;
13
- use crate :: ops:: { Bound , OneSidedRange , Range , RangeBounds , RangeInclusive } ;
13
+ use crate :: ops:: { OneSidedRange , OneSidedRangeBound , Range , RangeBounds , RangeInclusive } ;
14
14
use crate :: panic:: const_panic;
15
15
use crate :: simd:: { self , Simd } ;
16
16
use crate :: ub_checks:: assert_unsafe_precondition;
@@ -83,14 +83,12 @@ pub use raw::{from_raw_parts, from_raw_parts_mut};
83
83
/// which to split. Returns `None` if the split index would overflow.
84
84
#[ inline]
85
85
fn split_point_of ( range : impl OneSidedRange < usize > ) -> Option < ( Direction , usize ) > {
86
- use Bound :: * ;
87
-
88
- Some ( match ( range. start_bound ( ) , range. end_bound ( ) ) {
89
- ( Unbounded , Excluded ( i) ) => ( Direction :: Front , * i) ,
90
- ( Unbounded , Included ( i) ) => ( Direction :: Front , i. checked_add ( 1 ) ?) ,
91
- ( Excluded ( i) , Unbounded ) => ( Direction :: Back , i. checked_add ( 1 ) ?) ,
92
- ( Included ( i) , Unbounded ) => ( Direction :: Back , * i) ,
93
- _ => unreachable ! ( ) ,
86
+ use OneSidedRangeBound :: { End , EndInclusive , StartInclusive } ;
87
+
88
+ Some ( match range. bound ( ) {
89
+ ( StartInclusive , i) => ( Direction :: Back , i) ,
90
+ ( End , i) => ( Direction :: Front , i) ,
91
+ ( EndInclusive , i) => ( Direction :: Front , i. checked_add ( 1 ) ?) ,
94
92
} )
95
93
}
96
94
@@ -4294,25 +4292,25 @@ impl<T> [T] {
4294
4292
///
4295
4293
/// # Examples
4296
4294
///
4297
- /// Taking the first three elements of a slice:
4295
+ /// Splitting off the first three elements of a slice:
4298
4296
///
4299
4297
/// ```
4300
4298
/// #![feature(slice_take)]
4301
4299
///
4302
4300
/// let mut slice: &[_] = &['a', 'b', 'c', 'd'];
4303
- /// let mut first_three = slice.take (..3).unwrap();
4301
+ /// let mut first_three = slice.split_off (..3).unwrap();
4304
4302
///
4305
4303
/// assert_eq!(slice, &['d']);
4306
4304
/// assert_eq!(first_three, &['a', 'b', 'c']);
4307
4305
/// ```
4308
4306
///
4309
- /// Taking the last two elements of a slice:
4307
+ /// Splitting off the last two elements of a slice:
4310
4308
///
4311
4309
/// ```
4312
4310
/// #![feature(slice_take)]
4313
4311
///
4314
4312
/// let mut slice: &[_] = &['a', 'b', 'c', 'd'];
4315
- /// let mut tail = slice.take (2..).unwrap();
4313
+ /// let mut tail = slice.split_off (2..).unwrap();
4316
4314
///
4317
4315
/// assert_eq!(slice, &['a', 'b']);
4318
4316
/// assert_eq!(tail, &['c', 'd']);
@@ -4325,16 +4323,19 @@ impl<T> [T] {
4325
4323
///
4326
4324
/// let mut slice: &[_] = &['a', 'b', 'c', 'd'];
4327
4325
///
4328
- /// assert_eq!(None, slice.take (5..));
4329
- /// assert_eq!(None, slice.take (..5));
4330
- /// assert_eq!(None, slice.take (..=4));
4326
+ /// assert_eq!(None, slice.split_off (5..));
4327
+ /// assert_eq!(None, slice.split_off (..5));
4328
+ /// assert_eq!(None, slice.split_off (..=4));
4331
4329
/// let expected: &[char] = &['a', 'b', 'c', 'd'];
4332
- /// assert_eq!(Some(expected), slice.take (..4));
4330
+ /// assert_eq!(Some(expected), slice.split_off (..4));
4333
4331
/// ```
4334
4332
#[ inline]
4335
4333
#[ must_use = "method does not modify the slice if the range is out of bounds" ]
4336
4334
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4337
- pub fn take < ' a , R : OneSidedRange < usize > > ( self : & mut & ' a Self , range : R ) -> Option < & ' a Self > {
4335
+ pub fn split_off < ' a , R : OneSidedRange < usize > > (
4336
+ self : & mut & ' a Self ,
4337
+ range : R ,
4338
+ ) -> Option < & ' a Self > {
4338
4339
let ( direction, split_index) = split_point_of ( range) ?;
4339
4340
if split_index > self . len ( ) {
4340
4341
return None ;
@@ -4363,13 +4364,13 @@ impl<T> [T] {
4363
4364
///
4364
4365
/// # Examples
4365
4366
///
4366
- /// Taking the first three elements of a slice:
4367
+ /// Splitting off the first three elements of a slice:
4367
4368
///
4368
4369
/// ```
4369
4370
/// #![feature(slice_take)]
4370
4371
///
4371
4372
/// let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd'];
4372
- /// let mut first_three = slice.take_mut (..3).unwrap();
4373
+ /// let mut first_three = slice.split_off_mut (..3).unwrap();
4373
4374
///
4374
4375
/// assert_eq!(slice, &mut ['d']);
4375
4376
/// assert_eq!(first_three, &mut ['a', 'b', 'c']);
@@ -4381,7 +4382,7 @@ impl<T> [T] {
4381
4382
/// #![feature(slice_take)]
4382
4383
///
4383
4384
/// let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd'];
4384
- /// let mut tail = slice.take_mut (2..).unwrap();
4385
+ /// let mut tail = slice.split_off_mut (2..).unwrap();
4385
4386
///
4386
4387
/// assert_eq!(slice, &mut ['a', 'b']);
4387
4388
/// assert_eq!(tail, &mut ['c', 'd']);
@@ -4394,16 +4395,16 @@ impl<T> [T] {
4394
4395
///
4395
4396
/// let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd'];
4396
4397
///
4397
- /// assert_eq!(None, slice.take_mut (5..));
4398
- /// assert_eq!(None, slice.take_mut (..5));
4399
- /// assert_eq!(None, slice.take_mut (..=4));
4398
+ /// assert_eq!(None, slice.split_off_mut (5..));
4399
+ /// assert_eq!(None, slice.split_off_mut (..5));
4400
+ /// assert_eq!(None, slice.split_off_mut (..=4));
4400
4401
/// let expected: &mut [_] = &mut ['a', 'b', 'c', 'd'];
4401
- /// assert_eq!(Some(expected), slice.take_mut (..4));
4402
+ /// assert_eq!(Some(expected), slice.split_off_mut (..4));
4402
4403
/// ```
4403
4404
#[ inline]
4404
4405
#[ must_use = "method does not modify the slice if the range is out of bounds" ]
4405
4406
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4406
- pub fn take_mut < ' a , R : OneSidedRange < usize > > (
4407
+ pub fn split_off_mut < ' a , R : OneSidedRange < usize > > (
4407
4408
self : & mut & ' a mut Self ,
4408
4409
range : R ,
4409
4410
) -> Option < & ' a mut Self > {
@@ -4435,14 +4436,14 @@ impl<T> [T] {
4435
4436
/// #![feature(slice_take)]
4436
4437
///
4437
4438
/// let mut slice: &[_] = &['a', 'b', 'c'];
4438
- /// let first = slice.take_first ().unwrap();
4439
+ /// let first = slice.split_off_first ().unwrap();
4439
4440
///
4440
4441
/// assert_eq!(slice, &['b', 'c']);
4441
4442
/// assert_eq!(first, &'a');
4442
4443
/// ```
4443
4444
#[ inline]
4444
4445
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4445
- pub fn take_first < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4446
+ pub fn split_off_first < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4446
4447
let ( first, rem) = self . split_first ( ) ?;
4447
4448
* self = rem;
4448
4449
Some ( first)
@@ -4459,15 +4460,15 @@ impl<T> [T] {
4459
4460
/// #![feature(slice_take)]
4460
4461
///
4461
4462
/// let mut slice: &mut [_] = &mut ['a', 'b', 'c'];
4462
- /// let first = slice.take_first_mut ().unwrap();
4463
+ /// let first = slice.split_off_first_mut ().unwrap();
4463
4464
/// *first = 'd';
4464
4465
///
4465
4466
/// assert_eq!(slice, &['b', 'c']);
4466
4467
/// assert_eq!(first, &'d');
4467
4468
/// ```
4468
4469
#[ inline]
4469
4470
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4470
- pub fn take_first_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4471
+ pub fn split_off_first_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4471
4472
let ( first, rem) = mem:: take ( self ) . split_first_mut ( ) ?;
4472
4473
* self = rem;
4473
4474
Some ( first)
@@ -4484,14 +4485,14 @@ impl<T> [T] {
4484
4485
/// #![feature(slice_take)]
4485
4486
///
4486
4487
/// let mut slice: &[_] = &['a', 'b', 'c'];
4487
- /// let last = slice.take_last ().unwrap();
4488
+ /// let last = slice.split_off_last ().unwrap();
4488
4489
///
4489
4490
/// assert_eq!(slice, &['a', 'b']);
4490
4491
/// assert_eq!(last, &'c');
4491
4492
/// ```
4492
4493
#[ inline]
4493
4494
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4494
- pub fn take_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4495
+ pub fn split_off_last < ' a > ( self : & mut & ' a Self ) -> Option < & ' a T > {
4495
4496
let ( last, rem) = self . split_last ( ) ?;
4496
4497
* self = rem;
4497
4498
Some ( last)
@@ -4508,15 +4509,15 @@ impl<T> [T] {
4508
4509
/// #![feature(slice_take)]
4509
4510
///
4510
4511
/// let mut slice: &mut [_] = &mut ['a', 'b', 'c'];
4511
- /// let last = slice.take_last_mut ().unwrap();
4512
+ /// let last = slice.split_off_last_mut ().unwrap();
4512
4513
/// *last = 'd';
4513
4514
///
4514
4515
/// assert_eq!(slice, &['a', 'b']);
4515
4516
/// assert_eq!(last, &'d');
4516
4517
/// ```
4517
4518
#[ inline]
4518
4519
#[ unstable( feature = "slice_take" , issue = "62280" ) ]
4519
- pub fn take_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4520
+ pub fn split_off_last_mut < ' a > ( self : & mut & ' a mut Self ) -> Option < & ' a mut T > {
4520
4521
let ( last, rem) = mem:: take ( self ) . split_last_mut ( ) ?;
4521
4522
* self = rem;
4522
4523
Some ( last)
0 commit comments