fn remove_connection(&mut self, connection: Arc<Connection>) {
        let ptr = Arc::as_ptr(&connection);

        let maybe_remove_in_vec = |v: &mut Vec<Arc<Connection>>| -> bool {
            let maybe_idx = v
                .iter()
                .enumerate()
                .find(|(_, other_conn)| Arc::ptr_eq(&connection, other_conn))
                .map(|(idx, _)| idx);
            match maybe_idx {
                Some(idx) => {
                    v.swap_remove(idx);
                    true
                }
                None => false,
            }
        };

        // First, look it up in the shard bucket
        // We might have resharded, so the bucket might not exist anymore
        let shard_id = connection
            .get_shard_info()
            .as_ref()
            .map_or(0, |s| s.shard as usize);
        if shard_id < self.conns.len() && maybe_remove_in_vec(&mut self.conns[shard_id]) {
            trace!(
                "[{}] Connection {:p} removed from shard {} pool, now there is {} for the shard, total {}",
                self.address,
                ptr,
                shard_id,
                self.conns[shard_id].len(),
                self.active_connection_count(),
            );
            self.update_shared_conns();
            return;
        }

        // If we didn't find it, it might sit in the excess_connections bucket
        if maybe_remove_in_vec(&mut self.excess_connections) {
            trace!(
                "[{}] Connection {:p} removed from excess connection pool",
                self.address,
                ptr,
            );
            return;
        }

        trace!(
            "[{}] Connection {:p} was already removed",
            self.address,
            ptr,
        );
    }
// Removes given connection from the pool. It looks both into active
// connections and excess connections.
Removes given connection from the pool. It looks both into active
connections and excess connections.
Removes given connection from the pool . It looks both into active connections and excess connections .
fn remove_connection(&mut self, connection: Arc<Connection>) {
        let ptr = Arc::as_ptr(&connection);
        let maybe_remove_in_vec = |v: &mut Vec<Arc<Connection>>| -> bool {
            let maybe_idx = v
                .iter()
                .enumerate()
                .find(|(_, other_conn)| Arc::ptr_eq(&connection, other_conn))
                .map(|(idx, _)| idx);
            match maybe_idx {
                Some(idx) => {
                    v.swap_remove(idx);
                    true
                }
                None => false,
            }
        };
        // First, look it up in the shard bucket
        // We might have resharded, so the bucket might not exist anymore
        let shard_id = connection
            .get_shard_info()
            .as_ref()
            .map_or(0, |s| s.shard as usize);
        if shard_id < self.conns.len() && maybe_remove_in_vec(&mut self.conns[shard_id]) {
            trace!(
                "[{}] Connection {:p} removed from shard {} pool, now there is {} for the shard, total {}",
                self.address,
                ptr,
                shard_id,
                self.conns[shard_id].len(),
                self.active_connection_count(),
            );
            self.update_shared_conns();
            return;
        }
        // If we didn't find it, it might sit in the excess_connections bucket
        if maybe_remove_in_vec(&mut self.excess_connections) {
            trace!(
                "[{}] Connection {:p} removed from excess connection pool",
                self.address,
                ptr,
            );
            return;
        }
        trace!(
            "[{}] Connection {:p} was already removed",
            self.address,
            ptr,
        );
    }
fn remove_connection ( & mut self , connection : Arc < Connection > ) { let ptr = Arc :: as_ptr ( & connection ) ; let maybe_remove_in_vec = | v : & mut Vec < Arc < Connection > > | -> bool { let maybe_idx = v . iter ( ) . enumerate ( ) . find ( | ( _ , other_conn ) | Arc :: ptr_eq ( & connection , other_conn ) ) . map ( | ( idx , _ ) | idx ) ; match maybe_idx { Some ( idx ) => { v . swap_remove ( idx ) ; true } None => false , } } ; // First, look it up in the shard bucket // We might have resharded, so the bucket might not exist anymore let shard_id = connection . get_shard_info ( ) . as_ref ( ) . map_or ( 0 , | s | s . shard as usize ) ; if shard_id < self . conns . len ( ) && maybe_remove_in_vec ( & mut self . conns [ shard_id ] ) { trace ! ( " " self address ptr shard_id self conns [ shard_id ] len ( ) self active_connection_count ( ) ) ; self . update_shared_conns ( ) ; return ; } // If we didn't find it, it might sit in the excess_connections bucket if maybe_remove_in_vec ( & mut self . excess_connections ) { trace ! ( " " self address ptr ) ; return ; } trace ! ( " " self address ptr ) ; }
Removes given connection from the pool.
Removes given connection from the pool .
&mut self
connection
Arc<Connection>
&mut self
connection
Arc<Connection>