fn insert(&mut self, index: usize, element: Unconfirmed) {
        // get raw_index on txs
        let raw_index = match self.0.iter().filter(|tx| tx.is_some()).nth(index) {
            // note: item is some type
            Some(item) => self.position(&item.as_ref().unwrap().hash).unwrap(),
            None => {
                if 0 < index {
                    panic!("index is out of bounds");
                } else {
                    // vec is empty
                    self.0.push_back(Some(element));
                    return;
                }
            },
        };

        // check index-1 is none and replace
        if 0 < raw_index {
            let item = self.0.get_mut(raw_index - 1).unwrap();
            if item.is_none() {
                item.replace(element);
                return;
            }
        }

        // check index-2 is none and replace
        if 1 < raw_index {
            let back_index = raw_index - 2;
            if self.0.get(back_index).unwrap().is_none() {
                self.0.get_mut(back_index).unwrap().replace(element);
                self.0.swap(back_index, raw_index - 1);
                return;
            }
        }

        // check index+1 is none and replace
        if raw_index + 1 < self.0.len() {
            let next_index = raw_index + 1;
            if self.0.get(next_index).unwrap().is_none() {
                self.0.get_mut(next_index).unwrap().replace(element);
                self.0.swap(raw_index, next_index);
                return;
            }
        }

        // not found empty item near and insert
        self.0.insert(raw_index, Some(element));
    }
/// insert a item before the index specified
insert a item before the index specified
insert a item before the index specified
fn insert(&mut self, index: usize, element: Unconfirmed) {
        // get raw_index on txs
        let raw_index = match self.0.iter().filter(|tx| tx.is_some()).nth(index) {
            // note: item is some type
            Some(item) => self.position(&item.as_ref().unwrap().hash).unwrap(),
            None => {
                if 0 < index {
                    panic!("index is out of bounds");
                } else {
                    // vec is empty
                    self.0.push_back(Some(element));
                    return;
                }
            },
        };
        // check index-1 is none and replace
        if 0 < raw_index {
            let item = self.0.get_mut(raw_index - 1).unwrap();
            if item.is_none() {
                item.replace(element);
                return;
            }
        }
        // check index-2 is none and replace
        if 1 < raw_index {
            let back_index = raw_index - 2;
            if self.0.get(back_index).unwrap().is_none() {
                self.0.get_mut(back_index).unwrap().replace(element);
                self.0.swap(back_index, raw_index - 1);
                return;
            }
        }
        // check index+1 is none and replace
        if raw_index + 1 < self.0.len() {
            let next_index = raw_index + 1;
            if self.0.get(next_index).unwrap().is_none() {
                self.0.get_mut(next_index).unwrap().replace(element);
                self.0.swap(raw_index, next_index);
                return;
            }
        }
        // not found empty item near and insert
        self.0.insert(raw_index, Some(element));
    }
fn insert ( & mut self , index : usize , element : Unconfirmed ) { // get raw_index on txs let raw_index = match self . 0 . iter ( ) . filter ( | tx | tx . is_some ( ) ) . nth ( index ) { // note: item is some type Some ( item ) => self . position ( & item . as_ref ( ) . unwrap ( ) . hash ) . unwrap ( ) , None => { if 0 < index { panic ! ( " " ) ; } else { // vec is empty self . 0 . push_back ( Some ( element ) ) ; return ; } } , } ; // check index-1 is none and replace if 0 < raw_index { let item = self . 0 . get_mut ( raw_index - 1 ) . unwrap ( ) ; if item . is_none ( ) { item . replace ( element ) ; return ; } } // check index-2 is none and replace if 1 < raw_index { let back_index = raw_index - 2 ; if self . 0 . get ( back_index ) . unwrap ( ) . is_none ( ) { self . 0 . get_mut ( back_index ) . unwrap ( ) . replace ( element ) ; self . 0 . swap ( back_index , raw_index - 1 ) ; return ; } } // check index+1 is none and replace if raw_index + 1 < self . 0 . len ( ) { let next_index = raw_index + 1 ; if self . 0 . get ( next_index ) . unwrap ( ) . is_none ( ) { self . 0 . get_mut ( next_index ) . unwrap ( ) . replace ( element ) ; self . 0 . swap ( raw_index , next_index ) ; return ; } } // not found empty item near and insert self . 0 . insert ( raw_index , Some ( element ) ) ; }
insert a item before the index specified
insert a item before the index specified
&mut self
index
usize
element
Unconfirmed
&mut self
index
usize
element
Unconfirmed