pub struct UniAddr { /* private fields */ }Expand description
A unified address type that can represent:
std::net::SocketAddrunix::SocketAddr(a wrapper overstd::os::unix::net::SocketAddr)- A host name with port. See
ToSocketAddrs.
§Parsing Behaviour
- Checks if the address started with
UNIX_URI_PREFIX: parse as a UDS address. - Checks if the address is started with a alphabetic character (a-z, A-Z): treat as a host name. Notes that we will not validate if the host name is valid.
- Tries to parse as a network socket address.
- Otherwise, treats the input as a host name.
Implementations§
Source§impl UniAddr
impl UniAddr
Sourcepub const fn as_inner(&self) -> &UniAddrInner
pub const fn as_inner(&self) -> &UniAddrInner
Returns a reference to the inner value.
Source§impl UniAddr
impl UniAddr
Sourcepub fn new(addr: &str) -> Result<Self, ParseError>
pub fn new(addr: &str) -> Result<Self, ParseError>
Sourcepub fn new_host(
addr: &str,
parsed: Option<(&str, u16)>,
) -> Result<Self, ParseError>
pub fn new_host( addr: &str, parsed: Option<(&str, u16)>, ) -> Result<Self, ParseError>
Creates a new UniAddr from a string containing a host name and port,
like example.com:8080.
§Errors
ParseError::InvalidHostif the host name is invalid.ParseError::InvalidPortif the port is invalid.
Sourcepub fn blocking_resolve_socket_addrs(&mut self) -> Result<()>
pub fn blocking_resolve_socket_addrs(&mut self) -> Result<()>
Resolves the address if it is a host name.
By default, we utilize the method ToSocketAddrs::to_socket_addrs
provided by the standard library to perform DNS resolution, which is a
blocking operation and may take an arbitrary amount of time to
complete, use with caution when called in asynchronous contexts.
§Errors
Resolution failure, or if no socket address resolved.
Sourcepub fn blocking_resolve_socket_addrs_with<F, A>(&mut self, f: F) -> Result<()>
pub fn blocking_resolve_socket_addrs_with<F, A>(&mut self, f: F) -> Result<()>
Resolves the address if it is a host name using a custom resolver function.
§Errors
Resolution failure, or if no socket address resolved.
Sourcepub async fn resolve_socket_addrs(&mut self) -> Result<()>
pub async fn resolve_socket_addrs(&mut self) -> Result<()>
Asynchronously resolves the address if it is a host name.
This method will spawn a blocking Tokio task to perform the resolution
using ToSocketAddrs::to_socket_addrs provided by the standard
library.
§Errors
Resolution failure, or if no socket address resolved.
Methods from Deref<Target = UniAddrInner>§
Trait Implementations§
Source§impl AsRef<UniAddrInner> for UniAddr
impl AsRef<UniAddrInner> for UniAddr
Source§fn as_ref(&self) -> &UniAddrInner
fn as_ref(&self) -> &UniAddrInner
Source§impl<'de> Deserialize<'de> for UniAddr
Available on crate feature feat-serde only.
impl<'de> Deserialize<'de> for UniAddr
feat-serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<SocketAddr> for UniAddr
impl From<SocketAddr> for UniAddr
Source§fn from(addr: SocketAddr) -> Self
fn from(addr: SocketAddr) -> Self
Source§impl From<SocketAddr> for UniAddr
Available on Unix only.
impl From<SocketAddr> for UniAddr
Source§fn from(addr: SocketAddr) -> Self
fn from(addr: SocketAddr) -> Self
Source§impl From<SocketAddr> for UniAddr
Available on Unix and crate feature feat-tokio only.
impl From<SocketAddr> for UniAddr
feat-tokio only.