pub fn remove(&mut self, index: usize) -> Option<A::Item> {
        if self.is_empty() || self.len() <= index {
            return None;
        }

        // There are three main cases:
        //  Elements are contiguous
        //  Elements are discontiguous and the removal is in the tail section
        //  Elements are discontiguous and the removal is in the head section
        //      - special case when elements are technically contiguous,
        //        but self.head = 0
        //
        // For each of those there are two more cases:
        //  Insert is closer to tail
        //  Insert is closer to head
        //
        // Key: H - self.head
        //      T - self.tail
        //      o - Valid element
        //      x - Element marked for removal
        //      R - Indicates element that is being removed
        //      M - Indicates element was moved

        let idx = Self::wrap_add(self.tail(), index);

        let elem = unsafe { Some(self.buffer_read(idx)) };

        let distance_to_tail = index;
        let distance_to_head = self.len() - index;

        let contiguous = self.is_contiguous();

        match (
            contiguous,
            distance_to_tail <= distance_to_head,
            idx >= self.tail(),
        ) {
            (true, true, _) => {
                unsafe {
                    // contiguous, remove closer to tail:
                    //
                    //             T   R         H
                    //      [. . . o o x o o o o . . . . . .]
                    //
                    //               T           H
                    //      [. . . . o o o o o o . . . . . .]
                    //               M M

                    let tail = self.tail();
                    self.copy(tail + 1, tail, index);
                    self.set_tail_forward();
                }
            }
            (true, false, _) => {
                unsafe {
                    // contiguous, remove closer to head:
                    //
                    //             T       R     H
                    //      [. . . o o o o x o o . . . . . .]
                    //
                    //             T           H
                    //      [. . . o o o o o o . . . . . . .]
                    //                     M M

                    let head = self.head();
                    self.copy(idx, idx + 1, head - idx - 1);
                    self.set_head_backward();
                }
            }
            (false, true, true) => {
                unsafe {
                    // discontiguous, remove closer to tail, tail section:
                    //
                    //                   H         T   R
                    //      [o o o o o o . . . . . o o x o o]
                    //
                    //                   H           T
                    //      [o o o o o o . . . . . . o o o o]
                    //                               M M

                    let tail = self.tail();
                    self.copy(tail + 1, tail, index);
                    self.set_tail_forward();
                }
            }
            (false, false, false) => {
                unsafe {
                    // discontiguous, remove closer to head, head section:
                    //
                    //               R     H           T
                    //      [o o o o x o o . . . . . . o o o]
                    //
                    //                   H             T
                    //      [o o o o o o . . . . . . . o o o]
                    //               M M

                    let head = self.head();
                    self.copy(idx, idx + 1, head - idx - 1);
                    self.set_head_backward();
                }
            }
            (false, false, true) => {
                unsafe {
                    // discontiguous, remove closer to head, tail section:
                    //
                    //             H           T         R
                    //      [o o o . . . . . . o o o o o x o]
                    //
                    //           H             T
                    //      [o o . . . . . . . o o o o o o o]
                    //       M M                         M M
                    //
                    // or quasi-discontiguous, remove next to head, tail section:
                    //
                    //       H                 T         R
                    //      [. . . . . . . . . o o o o o x o]
                    //
                    //                         T           H
                    //      [. . . . . . . . . o o o o o o .]
                    //                                   M

                    // draw in elements in the tail section
                    self.copy(idx, idx + 1, A::capacity() - idx - 1);

                    // Prevents underflow.
                    if self.head() != 0 {
                        // copy first element into empty spot
                        self.copy(A::capacity() - 1, 0, 1);

                        // move elements in the head section backwards
                        let head = self.head();
                        self.copy(0, 1, head - 1);
                    }

                    self.set_head_backward();
                }
            }
            (false, true, false) => {
                unsafe {
                    // discontiguous, remove closer to tail, head section:
                    //
                    //           R               H     T
                    //      [o o x o o o o o o o . . . o o o]
                    //
                    //                           H       T
                    //      [o o o o o o o o o o . . . . o o]
                    //       M M M                       M M

                    let tail = self.tail();
                    // draw in elements up to idx
                    self.copy(1, 0, idx);

                    // copy last element into empty spot
                    self.copy(0, A::capacity() - 1, 1);

                    // move elements from tail to end forward, excluding the last one
                    self.copy(tail + 1, tail, A::capacity() - tail - 1);

                    self.set_tail_forward();
                }
            }
        }

        return elem;
    }
/// Removes and returns the element at `index` from the `ArrayDeque`.
/// Whichever end is closer to the removal point will be moved to make
/// room, and all the affected elements will be moved to new positions.
/// Returns `None` if `index` is out of bounds.
///
/// Element at index 0 is the front of the queue.
///
/// # Examples
///
/// ```
/// use arraydeque::ArrayDeque;
///
/// let mut buf: ArrayDeque<[_; 3]> = ArrayDeque::new();
///
/// buf.push_back(0);
/// buf.push_back(1);
/// buf.push_back(2);
///
/// assert_eq!(buf.remove(1), Some(1));
/// assert_eq!(buf, vec![0, 2].into());
/// ```
Removes and returns the element at `index` from the `ArrayDeque`.
Whichever end is closer to the removal point will be moved to make
room, and all the affected elements will be moved to new positions.
Returns `None` if `index` is out of bounds.

Element at index 0 is the front of the queue.
Removes and returns the element at ` index ` from the ` ArrayDeque ` . Whichever end is closer to the removal point will be moved to make room and all the affected elements will be moved to new positions . Returns ` None ` if ` index ` is out of bounds . Element at index 0 is the front of the queue .
pub fn remove(&mut self, index: usize) -> Option<A::Item> {
        if self.is_empty() || self.len() <= index {
            return None;
        }
        // There are three main cases:
        //  Elements are contiguous
        //  Elements are discontiguous and the removal is in the tail section
        //  Elements are discontiguous and the removal is in the head section
        //      - special case when elements are technically contiguous,
        //        but self.head = 0
        //
        // For each of those there are two more cases:
        //  Insert is closer to tail
        //  Insert is closer to head
        //
        // Key: H - self.head
        //      T - self.tail
        //      o - Valid element
        //      x - Element marked for removal
        //      R - Indicates element that is being removed
        //      M - Indicates element was moved
        let idx = Self::wrap_add(self.tail(), index);
        let elem = unsafe { Some(self.buffer_read(idx)) };
        let distance_to_tail = index;
        let distance_to_head = self.len() - index;
        let contiguous = self.is_contiguous();
        match (
            contiguous,
            distance_to_tail <= distance_to_head,
            idx >= self.tail(),
        ) {
            (true, true, _) => {
                unsafe {
                    // contiguous, remove closer to tail:
                    //
                    //             T   R         H
                    //      [. . . o o x o o o o . . . . . .]
                    //
                    //               T           H
                    //      [. . . . o o o o o o . . . . . .]
                    //               M M
                    let tail = self.tail();
                    self.copy(tail + 1, tail, index);
                    self.set_tail_forward();
                }
            }
            (true, false, _) => {
                unsafe {
                    // contiguous, remove closer to head:
                    //
                    //             T       R     H
                    //      [. . . o o o o x o o . . . . . .]
                    //
                    //             T           H
                    //      [. . . o o o o o o . . . . . . .]
                    //                     M M
                    let head = self.head();
                    self.copy(idx, idx + 1, head - idx - 1);
                    self.set_head_backward();
                }
            }
            (false, true, true) => {
                unsafe {
                    // discontiguous, remove closer to tail, tail section:
                    //
                    //                   H         T   R
                    //      [o o o o o o . . . . . o o x o o]
                    //
                    //                   H           T
                    //      [o o o o o o . . . . . . o o o o]
                    //                               M M
                    let tail = self.tail();
                    self.copy(tail + 1, tail, index);
                    self.set_tail_forward();
                }
            }
            (false, false, false) => {
                unsafe {
                    // discontiguous, remove closer to head, head section:
                    //
                    //               R     H           T
                    //      [o o o o x o o . . . . . . o o o]
                    //
                    //                   H             T
                    //      [o o o o o o . . . . . . . o o o]
                    //               M M
                    let head = self.head();
                    self.copy(idx, idx + 1, head - idx - 1);
                    self.set_head_backward();
                }
            }
            (false, false, true) => {
                unsafe {
                    // discontiguous, remove closer to head, tail section:
                    //
                    //             H           T         R
                    //      [o o o . . . . . . o o o o o x o]
                    //
                    //           H             T
                    //      [o o . . . . . . . o o o o o o o]
                    //       M M                         M M
                    //
                    // or quasi-discontiguous, remove next to head, tail section:
                    //
                    //       H                 T         R
                    //      [. . . . . . . . . o o o o o x o]
                    //
                    //                         T           H
                    //      [. . . . . . . . . o o o o o o .]
                    //                                   M
                    // draw in elements in the tail section
                    self.copy(idx, idx + 1, A::capacity() - idx - 1);
                    // Prevents underflow.
                    if self.head() != 0 {
                        // copy first element into empty spot
                        self.copy(A::capacity() - 1, 0, 1);
                        // move elements in the head section backwards
                        let head = self.head();
                        self.copy(0, 1, head - 1);
                    }
                    self.set_head_backward();
                }
            }
            (false, true, false) => {
                unsafe {
                    // discontiguous, remove closer to tail, head section:
                    //
                    //           R               H     T
                    //      [o o x o o o o o o o . . . o o o]
                    //
                    //                           H       T
                    //      [o o o o o o o o o o . . . . o o]
                    //       M M M                       M M
                    let tail = self.tail();
                    // draw in elements up to idx
                    self.copy(1, 0, idx);
                    // copy last element into empty spot
                    self.copy(0, A::capacity() - 1, 1);
                    // move elements from tail to end forward, excluding the last one
                    self.copy(tail + 1, tail, A::capacity() - tail - 1);
                    self.set_tail_forward();
                }
            }
        }
        return elem;
    }
pub fn remove ( & mut self , index : usize ) -> Option < A :: Item > { if self . is_empty ( ) || self . len ( ) <= index { return None ; } // There are three main cases: //  Elements are contiguous //  Elements are discontiguous and the removal is in the tail section //  Elements are discontiguous and the removal is in the head section //      - special case when elements are technically contiguous, //        but self.head = 0 // // For each of those there are two more cases: //  Insert is closer to tail //  Insert is closer to head // // Key: H - self.head //      T - self.tail //      o - Valid element //      x - Element marked for removal //      R - Indicates element that is being removed //      M - Indicates element was moved let idx = Self :: wrap_add ( self . tail ( ) , index ) ; let elem = unsafe { Some ( self . buffer_read ( idx ) ) } ; let distance_to_tail = index ; let distance_to_head = self . len ( ) - index ; let contiguous = self . is_contiguous ( ) ; match ( contiguous , distance_to_tail <= distance_to_head , idx >= self . tail ( ) , ) { ( true , true , _ ) => { unsafe { // contiguous, remove closer to tail: // //             T   R         H //      [. . . o o x o o o o . . . . . .] // //               T           H //      [. . . . o o o o o o . . . . . .] //               M M let tail = self . tail ( ) ; self . copy ( tail + 1 , tail , index ) ; self . set_tail_forward ( ) ; } } ( true , false , _ ) => { unsafe { // contiguous, remove closer to head: // //             T       R     H //      [. . . o o o o x o o . . . . . .] // //             T           H //      [. . . o o o o o o . . . . . . .] //                     M M let head = self . head ( ) ; self . copy ( idx , idx + 1 , head - idx - 1 ) ; self . set_head_backward ( ) ; } } ( false , true , true ) => { unsafe { // discontiguous, remove closer to tail, tail section: // //                   H         T   R //      [o o o o o o . . . . . o o x o o] // //                   H           T //      [o o o o o o . . . . . . o o o o] //                               M M let tail = self . tail ( ) ; self . copy ( tail + 1 , tail , index ) ; self . set_tail_forward ( ) ; } } ( false , false , false ) => { unsafe { // discontiguous, remove closer to head, head section: // //               R     H           T //      [o o o o x o o . . . . . . o o o] // //                   H             T //      [o o o o o o . . . . . . . o o o] //               M M let head = self . head ( ) ; self . copy ( idx , idx + 1 , head - idx - 1 ) ; self . set_head_backward ( ) ; } } ( false , false , true ) => { unsafe { // discontiguous, remove closer to head, tail section: // //             H           T         R //      [o o o . . . . . . o o o o o x o] // //           H             T //      [o o . . . . . . . o o o o o o o] //       M M                         M M // // or quasi-discontiguous, remove next to head, tail section: // //       H                 T         R //      [. . . . . . . . . o o o o o x o] // //                         T           H //      [. . . . . . . . . o o o o o o .] //                                   M // draw in elements in the tail section self . copy ( idx , idx + 1 , A :: capacity ( ) - idx - 1 ) ; // Prevents underflow. if self . head ( ) != 0 { // copy first element into empty spot self . copy ( A :: capacity ( ) - 1 , 0 , 1 ) ; // move elements in the head section backwards let head = self . head ( ) ; self . copy ( 0 , 1 , head - 1 ) ; } self . set_head_backward ( ) ; } } ( false , true , false ) => { unsafe { // discontiguous, remove closer to tail, head section: // //           R               H     T //      [o o x o o o o o o o . . . o o o] // //                           H       T //      [o o o o o o o o o o . . . . o o] //       M M M                       M M let tail = self . tail ( ) ; // draw in elements up to idx self . copy ( 1 , 0 , idx ) ; // copy last element into empty spot self . copy ( 0 , A :: capacity ( ) - 1 , 1 ) ; // move elements from tail to end forward, excluding the last one self . copy ( tail + 1 , tail , A :: capacity ( ) - tail - 1 ) ; self . set_tail_forward ( ) ; } } } return elem ; }
Removes and returns the element at `index` from the `ArrayDeque`.
Removes and returns the element at ` index ` from the ` ArrayDeque ` .
&mut self
index
usize
examples
```
use arraydeque::ArrayDeque.

let mut buf: ArrayDeque<[_; 3]> = ArrayDeque::new().




` ` ` use arraydeque :: ArrayDeque . let mut buf : ArrayDeque< [ _ ; 3 ] > = ArrayDeque :: new () .