Struct std::os::unix::net::SocketAddr 1.10.0[−][src]
pub struct SocketAddr { /* fields omitted */ }
This is supported on Unix only.
Expand description
Implementations
Returns true
if the address is unnamed.
Examples
A named address:
use std::os::unix::net::UnixListener;
fn main() -> std::io::Result<()> {
let socket = UnixListener::bind("/tmp/sock")?;
let addr = socket.local_addr().expect("Couldn't get local address");
assert_eq!(addr.is_unnamed(), false);
Ok(())
}
RunAn unnamed address:
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::unbound()?;
let addr = socket.local_addr().expect("Couldn't get local address");
assert_eq!(addr.is_unnamed(), true);
Ok(())
}
RunReturns the contents of this address if it is a pathname
address.
Examples
With a pathname:
use std::os::unix::net::UnixListener;
use std::path::Path;
fn main() -> std::io::Result<()> {
let socket = UnixListener::bind("/tmp/sock")?;
let addr = socket.local_addr().expect("Couldn't get local address");
assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock")));
Ok(())
}
RunWithout a pathname:
use std::os::unix::net::UnixDatagram;
fn main() -> std::io::Result<()> {
let socket = UnixDatagram::unbound()?;
let addr = socket.local_addr().expect("Couldn't get local address");
assert_eq!(addr.as_pathname(), None);
Ok(())
}
RunTrait Implementations
Auto Trait Implementations
impl RefUnwindSafe for SocketAddr
impl Send for SocketAddr
impl Sync for SocketAddr
impl Unpin for SocketAddr
impl UnwindSafe for SocketAddr
Blanket Implementations
Mutably borrows from an owned value. Read more