pub fn pick_one(&self) -> Option<SocketAddr> {
        if self.addresses.len() == 0 {
            return None
        }
        let total_weight = self.addresses.iter().map(|&(w, _)| w).sum();
        if total_weight == 0 {
            // All addresses are equal
            return Some(thread_rng().choose(self.addresses).unwrap().1)
        }
        let mut n = thread_rng().gen_range(0, total_weight);
        for &(w, addr) in self.addresses {
            if n < w {
                return Some(addr);
            }
            n -= w;
        }
        unreachable!();
    }
/// Select one random address to connect to
///
/// This function selects a host according to the random distribution
/// according to the weights.
///
/// Returns `None` if the set is empty
Select one random address to connect to
This function selects a host according to the random distribution
according to the weights.

Returns `None` if the set is empty
Select one random address to connect to This function selects a host according to the random distribution according to the weights . Returns ` None ` if the set is empty
pub fn pick_one(&self) -> Option<SocketAddr> {
        if self.addresses.len() == 0 {
            return None
        }
        let total_weight = self.addresses.iter().map(|&(w, _)| w).sum();
        if total_weight == 0 {
            // All addresses are equal
            return Some(thread_rng().choose(self.addresses).unwrap().1)
        }
        let mut n = thread_rng().gen_range(0, total_weight);
        for &(w, addr) in self.addresses {
            if n < w {
                return Some(addr);
            }
            n -= w;
        }
        unreachable!();
    }
pub fn pick_one ( & self ) -> Option < SocketAddr > { if self . addresses . len ( ) == 0 { return None } let total_weight = self . addresses . iter ( ) . map ( | & ( w , _ ) | w ) . sum ( ) ; if total_weight == 0 { // All addresses are equal return Some ( thread_rng ( ) . choose ( self . addresses ) . unwrap ( ) . 1 ) } let mut n = thread_rng ( ) . gen_range ( 0 , total_weight ) ; for & ( w , addr ) in self . addresses { if n < w { return Some ( addr ) ; } n -= w ; } unreachable ! ( ) ; }
Select one random address to connect to
This function selects a host according to the random distribution
according to the weights.
Select one random address to connect to This function selects a host according to the random distribution according to the weights .
&self
&self