#[non_exhaustive]pub enum SocketAddr {
Inet(SocketAddr),
Unix(SocketAddr),
}
Expand description
Any address that Arti can listen on or connect to.
We use this type when we want to make streams without being concerned whether they are AF_UNIX streams, TCP streams, or so forth.
To avoid confusion, you might want to avoid importing this type directly.
Instead, import rtcompat::general
and refer to this type as general::SocketAddr
.
§String representation
Any general::SocketAddr
has up to two string representations:
-
A qualified representation, consisting of a schema (either “unix” or “inet”), followed by a single colon, followed by the address itself represented as a string.
Examples:
unix:/path/to/socket
,inet:127.0.0.1:9999
,inet:[::1]:9999
.The “unnamed” AF_UNIX address is represented as
unix:
. -
A unqualified representation, consisting of a
net::SocketAddr
address represented as a string.Examples:
127.0.0.1:9999
,[::1]:9999
.
Note that not every general::SocketAddr
has a string representation!
Currently, the ones that might not be representable are:
- “Abstract” AF_UNIX addresses (a Linux feature)
- AF_UNIX addresses whose path name is not UTF-8.
Note also that string representations may contain whitespace
or other unusual characters.
/var/run/arti socket
is a valid filename,
so unix:/var/run/arti socket
is a valid representation.
We may add new schemas in the future.
If we do, any new schema will begin with an ascii alphabetical character,
and will consist only of ascii alphanumeric characters,
the character -
, and the character _
.
§Network address representation
When representing a net::Socketaddr
address as a string,
we use the formats implemented by std::net::SocketAddr
’s
FromStr
implementation. In contrast with the textual representations of
Ipv4Addr
and Ipv6Addr
,
these formats are not currently very well specified by Rust.
Therefore we describe them here:
- A
SocketAddrV4
is encoded as:- an IPv4 address,
- a colon (
:
), - a 16-bit decimal integer.
- A
SocketAddrV6
is encoded as:- a left square bracket (
[
), - an IPv6 address,
- optionally, a percent sign (
%
) and a 32-bit decimal integer - a right square bracket (
]
), - a colon (
:
), - a 16-bit decimal integer.
- a left square bracket (
Note that the above implementation does not provide any way
to encode the flowinfo
member
of a SocketAddrV6
.
Any flowinfo
information set in an address
will therefore be lost when the address is encoded.
TODO: We should try to get Rust’s stdlib specify these formats, so we don’t have to. There is an open PR at https://github.com/rust-lang/rust/pull/131790.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Inet(SocketAddr)
An IPv4 or IPv6 address on the internet.
Unix(SocketAddr)
A local AF_UNIX address.
(Note that unix::SocketAddr
is unconstructable on platforms where it is not supported.)
Implementations§
Source§impl SocketAddr
impl SocketAddr
Sourcepub fn display_lossy(&self) -> DisplayLossy<'_>
pub fn display_lossy(&self) -> DisplayLossy<'_>
Return a wrapper object that can be used to display this address.
The resulting display might be lossy, depending on whether this address can be represented as a string.
The displayed format here is intentionally undocumented; it may change in the future.
Sourcepub fn try_to_string(&self) -> Option<String>
pub fn try_to_string(&self) -> Option<String>
If possible, return a qualified string representation for this address.
Otherwise return None.
Sourcepub fn as_pathname(&self) -> Option<&Path>
pub fn as_pathname(&self) -> Option<&Path>
If this address has an associated filesystem path, return that path.
Trait Implementations§
Source§impl<'a> Arbitrary<'a> for SocketAddr
impl<'a> Arbitrary<'a> for SocketAddr
Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<SocketAddr, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<SocketAddr, Error>
Self
from the given unstructured data. Read more§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self
from the entirety of the given
unstructured data. Read moreSource§impl Clone for SocketAddr
impl Clone for SocketAddr
Source§fn clone(&self) -> SocketAddr
fn clone(&self) -> SocketAddr
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SocketAddr
impl Debug for SocketAddr
Source§impl From<SocketAddr> for SocketAddr
impl From<SocketAddr> for SocketAddr
Source§fn from(value: SocketAddr) -> SocketAddr
fn from(value: SocketAddr) -> SocketAddr
Source§impl From<SocketAddr> for SocketAddr
impl From<SocketAddr> for SocketAddr
Source§fn from(value: SocketAddr) -> SocketAddr
fn from(value: SocketAddr) -> SocketAddr
Source§impl FromStr for SocketAddr
impl FromStr for SocketAddr
Source§type Err = AddrParseError
type Err = AddrParseError
Source§fn from_str(s: &str) -> Result<SocketAddr, <SocketAddr as FromStr>::Err>
fn from_str(s: &str) -> Result<SocketAddr, <SocketAddr as FromStr>::Err>
s
to return a value of this type. Read moreSource§impl NetStreamListener<SocketAddr> for Listener
impl NetStreamListener<SocketAddr> for Listener
Source§type Stream = Stream
type Stream = Stream
Self::incoming()
.Source§type Incoming = IncomingStreams
type Incoming = IncomingStreams
stream::Stream
] returned by Self::incoming()
.Source§fn incoming(self) -> IncomingStreams
fn incoming(self) -> IncomingStreams
stream::Stream
] that yields
streams and addresses.Source§fn local_addr(&self) -> IoResult<SocketAddr>
fn local_addr(&self) -> IoResult<SocketAddr>
Source§impl PartialEq for SocketAddr
impl PartialEq for SocketAddr
Source§fn eq(&self, other: &SocketAddr) -> bool
fn eq(&self, other: &SocketAddr) -> bool
Return true if two SocketAddr
s are equal.
For Inet
addresses, delegates to std::net::SocketAddr::eq
.
For Unix
addresses, treats two addresses as equal if any of the following is true:
- Both addresses have the same path.
- Both addresses are unnamed.
- (Linux only) Both addresses have the same abstract name.
Addresses of different types are always unequal.
Auto Trait Implementations§
impl Freeze for SocketAddr
impl RefUnwindSafe for SocketAddr
impl Send for SocketAddr
impl Sync for SocketAddr
impl Unpin for SocketAddr
impl UnwindSafe for SocketAddr
Blanket Implementations§
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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> NetStreamProvider<SocketAddr> for T
impl<T> NetStreamProvider<SocketAddr> for T
Source§type Stream = Stream
type Stream = Stream
Self::connect()
.Source§type Listener = Listener
type Listener = Listener
Self::listen()
.