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
impl Destination
Sourcepub fn new_with_host(secure: bool, host: impl Into<String>, port: u16) -> Self
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.
Sourcepub fn new_with_socket_addrs(
secure: bool,
addrs: impl IntoIterator<Item = SocketAddr>,
) -> Self
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.
Sourcepub fn from_url(url: &Url) -> Result<Self>
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.
Sourcepub fn to_url(&self) -> Result<Url>
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.
Sourcepub fn host(&self) -> Option<&str>
pub fn host(&self) -> Option<&str>
The host name used for resolution and certificate validation, or None for a bare-IP
destination.
Sourcepub fn port(&self) -> u16
pub fn port(&self) -> u16
The origin port. Pre-resolved addrs carry their own ports; this is
the port used when resolving the host.
Sourcepub fn addrs(&self) -> &[SocketAddr]
pub fn addrs(&self) -> &[SocketAddr]
The pre-resolved addresses to dial, or an empty slice to resolve the host.
Sourcepub fn alpn(&self) -> Option<&[Cow<'static, [u8]>]>
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.
Sourcepub fn with_addrs(self, addrs: impl IntoIterator<Item = SocketAddr>) -> Self
pub fn with_addrs(self, addrs: impl IntoIterator<Item = SocketAddr>) -> Self
Set the pre-resolved addresses to dial, replacing any already present.
Sourcepub fn set_addrs(
&mut self,
addrs: impl IntoIterator<Item = SocketAddr>,
) -> &mut Self
pub fn set_addrs( &mut self, addrs: impl IntoIterator<Item = SocketAddr>, ) -> &mut Self
Set the pre-resolved addresses to dial, replacing any already present.
Sourcepub fn with_alpn(
self,
alpn: impl IntoIterator<Item = Cow<'static, [u8]>>,
) -> Self
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.
Sourcepub fn set_alpn(
&mut self,
alpn: impl IntoIterator<Item = Cow<'static, [u8]>>,
) -> &mut Self
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.
Sourcepub fn without_alpn(self) -> Self
pub fn without_alpn(self) -> Self
Clear any per-connection ALPN override so this connection uses the connector’s configured default.
Sourcepub fn clear_alpn(&mut self) -> &mut Self
pub fn clear_alpn(&mut self) -> &mut Self
Clear any per-connection ALPN override so this connection uses the connector’s configured default.
Sourcepub fn with_secure(self, secure: bool) -> Self
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
impl Clone for Destination
Source§fn clone(&self) -> Destination
fn clone(&self) -> Destination
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more