pub enum SocketAddr {
Inet(SocketAddr),
Unix(SocketAddr),
}
Expand description
A unified address type that can represent both
std::net::SocketAddr
and unix::SocketAddr
(a wrapper over
std::os::unix::net::SocketAddr
).
§Notes
For Unix domain sockets addresses, serialization/deserialization will be
performed in URI format (see UNIX_URI_PREFIX
), which is different from
unix::SocketAddr
’s serialization/deserialization behaviour.
Variants§
Implementations§
Source§impl SocketAddr
impl SocketAddr
Sourcepub fn new(addr: &str) -> Result<Self>
pub fn new(addr: &str) -> Result<Self>
Creates a new SocketAddr
from its string representation.
The string can be in one of the following formats:
- Network socket address:
"127.0.0.1:8080"
,"[::1]:8080"
- Unix domain socket (pathname):
"unix:///run/listen.sock"
- Unix domain socket (abstract):
"unix://@abstract.unix.socket"
§Examples
// Network addresses
let addr_v4 = SocketAddr::new("127.0.0.1:8080").unwrap();
let addr_v6 = SocketAddr::new("[::1]:8080").unwrap();
// Unix domain sockets
let addr_unix_filename = SocketAddr::new("unix:///run/listen.sock").unwrap();
let addr_unix_abstract = SocketAddr::new("unix://@abstract.unix.socket").unwrap();
See unix::SocketAddr::new
for more details on Unix socket address
formats.
Sourcepub fn bind_std(&self) -> Result<StdListener>
pub fn bind_std(&self) -> Result<StdListener>
Binds a standard (TCP) listener to the address.
Sourcepub fn to_string_ext(&self) -> Option<String>
pub fn to_string_ext(&self) -> Option<String>
Serializes the address to a String
.
Trait Implementations§
Source§impl Clone for SocketAddr
impl Clone for SocketAddr
Source§fn clone(&self) -> SocketAddr
fn clone(&self) -> SocketAddr
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for SocketAddr
impl Debug for SocketAddr
Source§impl<'de> Deserialize<'de> for SocketAddr
impl<'de> Deserialize<'de> for SocketAddr
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Hash for SocketAddr
impl Hash for SocketAddr
Source§impl PartialEq for SocketAddr
impl PartialEq for SocketAddr
Source§impl Serialize for SocketAddr
impl Serialize for SocketAddr
impl Eq for SocketAddr
impl StructuralPartialEq for SocketAddr
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
Mutably borrows from an owned value. Read more