fn change_outgoing_state(
        &mut self,
        addr: SocketAddr,
        mut new_state: OutgoingState<H, E>,
    ) -> &mut Outgoing<H, E> {
        let (prev_state, new_outgoing) = match self.outgoing.entry(addr) {
            Entry::Vacant(vacant) => {
                let inserted = vacant.insert(Outgoing {
                    state: new_state,
                    is_unforgettable: false,
                });

                (None, inserted)
            }

            Entry::Occupied(occupied) => {
                let prev = occupied.into_mut();

                mem::swap(&mut prev.state, &mut new_state);

                // `new_state` and `prev.state` are swapped now.
                (Some(new_state), prev)
            }
        };

        // Update the routing table.
        match (&prev_state, &new_outgoing.state) {
            (Some(OutgoingState::Connected { .. }), OutgoingState::Connected { .. }) => {
                trace!("route unchanged, already connected");
            }

            // Dropping from connected to any other state requires clearing the route.
            (Some(OutgoingState::Connected { peer_id, .. }), _) => {
                debug!(%peer_id, "route removed");
                self.routes.remove(peer_id);
            }

            // Otherwise we have established a new route.
            (_, OutgoingState::Connected { peer_id, .. }) => {
                debug!(%peer_id, "route added");
                self.routes.insert(*peer_id, addr);
            }

            _ => {
                trace!("route unchanged");
            }
        }

        new_outgoing
    }
/// Changes the state of an outgoing connection.
///
/// Will trigger an update of the routing table if necessary. Does not emit any other
/// side-effects.
Changes the state of an outgoing connection.
Will trigger an update of the routing table if necessary. Does not emit any other
side-effects.
Changes the state of an outgoing connection . Will trigger an update of the routing table if necessary . Does not emit any other side - effects .
fn change_outgoing_state(
        &mut self,
        addr: SocketAddr,
        mut new_state: OutgoingState<H, E>,
    ) -> &mut Outgoing<H, E> {
        let (prev_state, new_outgoing) = match self.outgoing.entry(addr) {
            Entry::Vacant(vacant) => {
                let inserted = vacant.insert(Outgoing {
                    state: new_state,
                    is_unforgettable: false,
                });
                (None, inserted)
            }
            Entry::Occupied(occupied) => {
                let prev = occupied.into_mut();
                mem::swap(&mut prev.state, &mut new_state);
                // `new_state` and `prev.state` are swapped now.
                (Some(new_state), prev)
            }
        };
        // Update the routing table.
        match (&prev_state, &new_outgoing.state) {
            (Some(OutgoingState::Connected { .. }), OutgoingState::Connected { .. }) => {
                trace!("route unchanged, already connected");
            }
            // Dropping from connected to any other state requires clearing the route.
            (Some(OutgoingState::Connected { peer_id, .. }), _) => {
                debug!(%peer_id, "route removed");
                self.routes.remove(peer_id);
            }
            // Otherwise we have established a new route.
            (_, OutgoingState::Connected { peer_id, .. }) => {
                debug!(%peer_id, "route added");
                self.routes.insert(*peer_id, addr);
            }
            _ => {
                trace!("route unchanged");
            }
        }
        new_outgoing
    }
fn change_outgoing_state ( & mut self , addr : SocketAddr , mut new_state : OutgoingState < H , E > , ) -> & mut Outgoing < H , E > { let ( prev_state , new_outgoing ) = match self . outgoing . entry ( addr ) { Entry :: Vacant ( vacant ) => { let inserted = vacant . insert ( Outgoing { state : new_state , is_unforgettable : false , } ) ; ( None , inserted ) } Entry :: Occupied ( occupied ) => { let prev = occupied . into_mut ( ) ; mem :: swap ( & mut prev . state , & mut new_state ) ; // `new_state` and `prev.state` are swapped now. ( Some ( new_state ) , prev ) } } ; // Update the routing table. match ( & prev_state , & new_outgoing . state ) { ( Some ( OutgoingState :: Connected { .. } ) , OutgoingState :: Connected { .. } ) => { trace ! ( " " ) ; } // Dropping from connected to any other state requires clearing the route. ( Some ( OutgoingState :: Connected { peer_id , .. } ) , _ ) => { debug ! ( peer_id " " ) ; self . routes . remove ( peer_id ) ; } // Otherwise we have established a new route. ( _ , OutgoingState :: Connected { peer_id , .. } ) => { debug ! ( peer_id " " ) ; self . routes . insert ( * peer_id , addr ) ; } _ => { trace ! ( " " ) ; } } new_outgoing }
Changes the state of an outgoing connection.
Changes the state of an outgoing connection .
&mut self
addr
SocketAddr
new_state
OutgoingState<H, E>
&mut self
addr
SocketAddr
new_state
OutgoingState<H, E>