Struct Address

Source
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

Source

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

Source

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

Source

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

Source

pub fn iter(&self) -> PriorityIter<'_>

Returns iterator over WeightedSet’s starting from high priority set

Source

pub fn parse_list<I>(iter: I) -> Result<Address, AddrParseError>
where I: IntoIterator, I::Item: AsRef<str>,

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

Trait Implementations§

Source§

impl AsRef<Address> for Address

Source§

fn as_ref(&self) -> &Address

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Address

Source§

fn clone(&self) -> Address

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Address

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a [SocketAddr]> for Address

Source§

fn from(addr: &[SocketAddr]) -> Address

Converts to this type from the input type.
Source§

impl From<(IpAddr, u16)> for Address

Source§

fn from((ip, port): (IpAddr, u16)) -> Address

Converts to this type from the input type.
Source§

impl From<SocketAddr> for Address

Source§

fn from(addr: SocketAddr) -> Address

Converts to this type from the input type.
Source§

impl FromIterator<SocketAddr> for Address

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = SocketAddr>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for Address

Source§

fn eq(&self, other: &Address) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Address

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.