pub struct Addr { /* private fields */ }Expand description
A “host:port” network address.
The host can be a domain name, IPv4, or IPv6 address and the port must be a valid u16.
Addr ensures that the host part is a syntactically valid domain name or IP address.
It provides methods for DNS lookup, conversion to socket addresses, and serde
serialization/deserialization.
Implementations§
Source§impl Addr
impl Addr
Sourcepub fn new<T>(host: T, port: u16) -> Result<Addr, AddrError>
pub fn new<T>(host: T, port: u16) -> Result<Addr, AddrError>
Creates a new Addr from a host representation and a port number.
The host can be a domain name (e.g., “spideroak.com”), an IPv4 address string
(e.g., “192.168.1.1”), or an IPv6 address string (e.g., “::1”).
Returns an error if the host is not a valid domain name or IP address string.
§Errors
Returns AddrError::InvalidAddr if the host string is not a valid
domain name or IP address.
Sourcepub fn host(&self) -> &str
pub fn host(&self) -> &str
Returns a reference to the host part (domain name or IP address) of the Addr.
Sourcepub async fn lookup(&self) -> Result<impl Iterator<Item = SocketAddr>, Error>
pub async fn lookup(&self) -> Result<impl Iterator<Item = SocketAddr>, Error>
Performs an asynchronous DNS lookup for this Addr.
Resolves the host part of the address to one or more SocketAddr values.
Sourcepub fn to_socket_addrs(&self) -> impl ToSocketAddrs
pub fn to_socket_addrs(&self) -> impl ToSocketAddrs
Converts the Addr into a type that implements ToSocketAddrs.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Addr
impl<'de> Deserialize<'de> for Addr
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Addr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Addr, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl FromStr for Addr
impl FromStr for Addr
Source§fn from_str(s: &str) -> Result<Addr, <Addr as FromStr>::Err>
fn from_str(s: &str) -> Result<Addr, <Addr as FromStr>::Err>
Parses a string into an Addr.
The string can be in several forms:
host:port(e.g., “spideroak.com:80”, “192.168.1.1:8080”)- IPv6 address with port:
[ipv6_addr]:port(e.g., “[::1]:443”) - A string representation of a
SocketAddr(whichstd::net::SocketAddr::from_strcan parse).
This function first attempts to parse using SocketAddr, then falls
back to splitting the string at the first “:” character to parse the
host and port.
§Errors
Returns AddrError::InvalidAddr if the string format is invalid or the port
number is malformed.
Source§impl Ord for Addr
impl Ord for Addr
Source§impl PartialOrd for Addr
impl PartialOrd for Addr
Source§impl Serialize for Addr
impl Serialize for Addr
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl Copy for Addr
impl Eq for Addr
impl StructuralPartialEq for Addr
Auto Trait Implementations§
impl Freeze for Addr
impl RefUnwindSafe for Addr
impl Send for Addr
impl Sync for Addr
impl Unpin for Addr
impl UnsafeUnpin for Addr
impl UnwindSafe for Addr
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.