Skip to main content

Destination

Struct Destination 

Source
pub struct Destination { /* private fields */ }
Expand description

Everything a Connector needs to open one connection: where to dial, whether to wrap it in TLS, and any per-connection ALPN.

Construct with new_with_host — resolve a domain, or dial pre-resolved addresses while validating against the domain — or new_with_socket_addrs — dial pre-resolved addresses as a bare IP, with no SNI. There is deliberately no Default: a destination with neither a host nor any address is unconnectable, so each constructor fills at least one dial source.

Implementations§

Source§

impl Destination

Source

pub fn new_with_host(secure: bool, host: impl Into<String>, port: u16) -> Self

A destination identified by host name and port.

With no addrs added, the connector resolves host itself. Adding pre-resolved addresses dials those instead while still validating the certificate against host.

Source

pub fn new_with_socket_addrs( secure: bool, addrs: impl IntoIterator<Item = SocketAddr>, ) -> Self

A destination identified only by pre-resolved socket addresses: a bare-IP connection with no SNI, where TLS validates against the address actually dialed. The port is taken from the first address.

Source

pub fn from_url(url: &Url) -> Result<Self>

Build a destination from a URL: maps http/https to plaintext/TLS and extracts the host and port. An IP-literal host becomes a new_with_socket_addrs destination, so it is never sent to a resolver; a domain becomes a new_with_host destination.

§Errors

Returns an error if the scheme is neither http nor https, or the URL has no host or port.

Source

pub fn to_url(&self) -> Result<Url>

Reconstruct a URL for this destination’s origin, used by the default connect_to implementation to fall back to connect. Pre-resolved addresses and ALPN are not represented.

§Errors

Returns an error if the destination has neither a host nor any address, or the result does not parse as a URL.

Source

pub fn secure(&self) -> bool

Whether this destination should be reached over TLS.

Source

pub fn host(&self) -> Option<&str>

The host name used for resolution and certificate validation, or None for a bare-IP destination.

Source

pub fn port(&self) -> u16

The origin port. Pre-resolved addrs carry their own ports; this is the port used when resolving the host.

Source

pub fn addrs(&self) -> &[SocketAddr]

The pre-resolved addresses to dial, or an empty slice to resolve the host.

Source

pub fn alpn(&self) -> Option<&[Cow<'static, [u8]>]>

The per-connection ALPN override: Some advertises exactly these protocols for this connection (Some([]) advertises none), None leaves the connector’s configured default in place.

Source

pub fn with_addrs(self, addrs: impl IntoIterator<Item = SocketAddr>) -> Self

Set the pre-resolved addresses to dial, replacing any already present.

Source

pub fn set_addrs( &mut self, addrs: impl IntoIterator<Item = SocketAddr>, ) -> &mut Self

Set the pre-resolved addresses to dial, replacing any already present.

Source

pub fn with_alpn( self, alpn: impl IntoIterator<Item = Cow<'static, [u8]>>, ) -> Self

Override the ALPN protocols to advertise for this connection, replacing any already present. An empty iterator advertises no ALPN at all; to instead defer to the connector’s configured default, use without_alpn.

Source

pub fn set_alpn( &mut self, alpn: impl IntoIterator<Item = Cow<'static, [u8]>>, ) -> &mut Self

Override the ALPN protocols to advertise for this connection, replacing any already present. An empty iterator advertises no ALPN at all; to instead defer to the connector’s configured default, use clear_alpn.

Source

pub fn without_alpn(self) -> Self

Clear any per-connection ALPN override so this connection uses the connector’s configured default.

Source

pub fn clear_alpn(&mut self) -> &mut Self

Clear any per-connection ALPN override so this connection uses the connector’s configured default.

Source

pub fn with_secure(self, secure: bool) -> Self

Return a copy of this destination with the secure flag overridden.

Trait Implementations§

Source§

impl Clone for Destination

Source§

fn clone(&self) -> Destination

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Destination

Source§

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

Formats the value using the given formatter. Read more

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.