@@ -30,11 +30,8 @@ extern crate core as std;
30
30
use std:: cmp;
31
31
use std:: iter;
32
32
use std:: mem;
33
+ use std:: ops:: { Bound , Deref , DerefMut , RangeBounds } ;
33
34
use std:: ptr;
34
- use std:: ops:: {
35
- Deref ,
36
- DerefMut ,
37
- } ;
38
35
use std:: slice;
39
36
40
37
// extra traits
@@ -55,11 +52,9 @@ use serde::{Serialize, Deserialize, Serializer, Deserializer};
55
52
mod array;
56
53
mod array_string;
57
54
mod char;
58
- mod range;
59
55
mod errors;
60
56
61
57
pub use crate :: array:: Array ;
62
- pub use crate :: range:: RangeArgument ;
63
58
use crate :: array:: Index ;
64
59
pub use crate :: array_string:: ArrayString ;
65
60
pub use crate :: errors:: CapacityError ;
@@ -572,7 +567,9 @@ impl<A: Array> ArrayVec<A> {
572
567
/// assert_eq!(&v[..], &[3]);
573
568
/// assert_eq!(&u[..], &[1, 2]);
574
569
/// ```
575
- pub fn drain < R : RangeArgument > ( & mut self , range : R ) -> Drain < A > {
570
+ pub fn drain < R > ( & mut self , range : R ) -> Drain < A >
571
+ where R : RangeBounds < usize >
572
+ {
576
573
// Memory safety
577
574
//
578
575
// When the Drain is first created, it shortens the length of
@@ -584,8 +581,22 @@ impl<A: Array> ArrayVec<A> {
584
581
// the hole, and the vector length is restored to the new length.
585
582
//
586
583
let len = self . len ( ) ;
587
- let start = range. start ( ) . unwrap_or ( 0 ) ;
588
- let end = range. end ( ) . unwrap_or ( len) ;
584
+ let start = match range. start_bound ( ) {
585
+ Bound :: Unbounded => 0 ,
586
+ Bound :: Included ( & i) => i,
587
+ Bound :: Excluded ( & i) => i. saturating_add ( 1 ) ,
588
+ } ;
589
+ let end = match range. end_bound ( ) {
590
+ Bound :: Excluded ( & j) => j,
591
+ Bound :: Included ( & j) => j. saturating_add ( 1 ) ,
592
+ Bound :: Unbounded => len,
593
+ } ;
594
+ self . drain_range ( start, end)
595
+ }
596
+
597
+ fn drain_range ( & mut self , start : usize , end : usize ) -> Drain < A >
598
+ {
599
+ let len = self . len ( ) ;
589
600
// bounds check happens here
590
601
let range_slice: * const _ = & self [ start..end] ;
591
602
0 commit comments