pub struct Address(/* private fields */);
Expand description
Address that nameservice has returned
We hide this structure to allow future additions. There is Builder
which provides a forward compatible way to build such address in a resolver
and there are methods to extract data from it.
Internally it’s an Arc
over a structure so it’s cheap to clone and you
can cache addresses.
Implementations§
Source§impl Address
impl Address
Sourcepub fn pick_one(&self) -> Option<SocketAddr>
pub fn pick_one(&self) -> Option<SocketAddr>
Select one random address to connect to
Picks a single address from the set of high priority addresses, with the random distribution according to the weights.
This method is stateless so it can’t find out that high priority addresses are all inaccessible and fallback addresses should be used.
Returns None
if address is empty
Sourcepub fn addresses_at(&self, priority: usize) -> OwnedAddressIter ⓘ
pub fn addresses_at(&self, priority: usize) -> OwnedAddressIter ⓘ
Returns an owned iterator over addresses at priority
This is similar to self.at(pri).addresses()
but returns an owned
object that implements IntoIterator. This might be useful for streams
and futures where borrowed objects don’t work
Sourcepub fn at(&self, priority: usize) -> WeightedSet<'_>
pub fn at(&self, priority: usize) -> WeightedSet<'_>
Returns the set of the hosts for the same priority
Note: original priorities are lost. This method has contiguous array
of sets of hosts. The highest priority hosts returned by .at(0)
.
If no hosts the priority exists returns an empty set
Use iter()
to iterate over WeightedSet
’s by priority
Sourcepub fn iter(&self) -> PriorityIter<'_> ⓘ
pub fn iter(&self) -> PriorityIter<'_> ⓘ
Returns iterator over WeightedSet
’s starting from high priority set
Sourcepub fn parse_list<I>(iter: I) -> Result<Address, AddrParseError>
pub fn parse_list<I>(iter: I) -> Result<Address, AddrParseError>
Parse a list of strings and put it into an address
This only uses one layer of addresses with same weights. And is mostly useful for unit tests