pub fn drain<R>(&mut self, range: R) -> Drain<T>
    where
        R: RangeBounds<usize>,
    {
        // Memory safety
        //
        // When the Drain is first created, it shortens the length of
        // the source vector to make sure no uninitialized or moved-from elements
        // are accessible at all if the Drain's destructor never gets to run.
        //
        // Drain will ptr::read out the values to remove.
        // When finished, remaining tail of the vec is copied back to cover
        // the hole, and the vector length is restored to the new length.
        //
        let len = self.len();
        let start = match range.start_bound() {
            Included(&n) => n,
            Excluded(&n) => n + 1,
            Unbounded => 0,
        };
        let end = match range.end_bound() {
            Included(&n) => n + 1,
            Excluded(&n) => n,
            Unbounded => len,
        };
        assert!(start <= end);
        assert!(end <= len);

        unsafe {
            // set self.vec length's to start, to be safe in case Drain is leaked
            self.set_len(start);
            // Use the borrow in the IterMut to indicate borrowing behavior of the
            // whole Drain iterator (like &mut T).
            let range_slice = slice::from_raw_parts_mut(self.as_mut_ptr().add(start), end - start);
            Drain {
                tail_start: end,
                tail_len: len - end,
                iter: range_slice.iter(),
                vec: NonNull::from(self),
            }
        }
    }
/// Creates a draining iterator that removes the specified range in the vector
/// and yields the removed items.
///
/// Note 1: The element range is removed even if the iterator is only
/// partially consumed or not consumed at all.
///
/// Note 2: It is unspecified how many elements are removed from the vector
/// if the `Drain` value is leaked.
///
/// # Panics
///
/// Panics if the starting point is greater than the end point or if
/// the end point is greater than the length of the vector.
///
/// # Examples
///
/// ```
/// use bumpalo::{Bump, collections::Vec};
///
/// let b = Bump::new();
///
/// let mut v = bumpalo::vec![in &b; 1, 2, 3];
///
/// let mut u: Vec<_> = Vec::new_in(&b);
/// u.extend(v.drain(1..));
///
/// assert_eq!(v, &[1]);
/// assert_eq!(u, &[2, 3]);
///
/// // A full range clears the vector
/// v.drain(..);
/// assert_eq!(v, &[]);
/// ```
Creates a draining iterator that removes the specified range in the vector
and yields the removed items.

Note 1: The element range is removed even if the iterator is only
partially consumed or not consumed at all.

Note 2: It is unspecified how many elements are removed from the vector
if the `Drain` value is leaked.
Creates a draining iterator that removes the specified range in the vector and yields the removed items . Note 1 : The element range is removed even if the iterator is only partially consumed or not consumed at all . Note 2 : It is unspecified how many elements are removed from the vector if the ` Drain ` value is leaked .
pub fn drain<R>(&mut self, range: R) -> Drain<T>
    where
        R: RangeBounds<usize>,
    {
        // Memory safety
        //
        // When the Drain is first created, it shortens the length of
        // the source vector to make sure no uninitialized or moved-from elements
        // are accessible at all if the Drain's destructor never gets to run.
        //
        // Drain will ptr::read out the values to remove.
        // When finished, remaining tail of the vec is copied back to cover
        // the hole, and the vector length is restored to the new length.
        //
        let len = self.len();
        let start = match range.start_bound() {
            Included(&n) => n,
            Excluded(&n) => n + 1,
            Unbounded => 0,
        };
        let end = match range.end_bound() {
            Included(&n) => n + 1,
            Excluded(&n) => n,
            Unbounded => len,
        };
        assert!(start <= end);
        assert!(end <= len);
        unsafe {
            // set self.vec length's to start, to be safe in case Drain is leaked
            self.set_len(start);
            // Use the borrow in the IterMut to indicate borrowing behavior of the
            // whole Drain iterator (like &mut T).
            let range_slice = slice::from_raw_parts_mut(self.as_mut_ptr().add(start), end - start);
            Drain {
                tail_start: end,
                tail_len: len - end,
                iter: range_slice.iter(),
                vec: NonNull::from(self),
            }
        }
    }
pub fn drain < R > ( & mut self , range : R ) -> Drain < T > where R : RangeBounds < usize > , { // Memory safety // // When the Drain is first created, it shortens the length of // the source vector to make sure no uninitialized or moved-from elements // are accessible at all if the Drain's destructor never gets to run. // // Drain will ptr::read out the values to remove. // When finished, remaining tail of the vec is copied back to cover // the hole, and the vector length is restored to the new length. // let len = self . len ( ) ; let start = match range . start_bound ( ) { Included ( & n ) => n , Excluded ( & n ) => n + 1 , Unbounded => 0 , } ; let end = match range . end_bound ( ) { Included ( & n ) => n + 1 , Excluded ( & n ) => n , Unbounded => len , } ; assert ! ( start end ) ; assert ! ( end len ) ; unsafe { // set self.vec length's to start, to be safe in case Drain is leaked self . set_len ( start ) ; // Use the borrow in the IterMut to indicate borrowing behavior of the // whole Drain iterator (like &mut T). let range_slice = slice :: from_raw_parts_mut ( self . as_mut_ptr ( ) . add ( start ) , end - start ) ; Drain { tail_start : end , tail_len : len - end , iter : range_slice . iter ( ) , vec : NonNull :: from ( self ) , } } }
Creates a draining iterator that removes the specified range in the vector
and yields the removed items.
Creates a draining iterator that removes the specified range in the vector and yields the removed items .
&mut self
range
R
&mut self
range
R
panics
Panics if the starting point is greater than the end point or if
the end point is greater than the length of the vector.
Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector .
examples
```
use bumpalo::{Bump, collections::Vec}.









A full range clears the vector
v.drain(..);
assert_eq!(v, &[]);
```
` ` ` use bumpalo :: { Bump collections :: Vec } . A full range clears the vector v . drain ( .. ) ; assert_eq! ( v & [] ) ; ` ` `