Struct std::os::unix::net::SocketAddr 1.10.0[−][src]
pub struct SocketAddr { /* fields omitted */ }
This is supported on Unix only.
Expand description
Implementations
如果地址未命名,则返回 true
。
Examples
命名地址:
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(()) }Run
一个未命名的地址:
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(()) }Run
如果它是 pathname
地址,则返回该地址的内容。
Examples
带有路径名:
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(()) }Run
没有路径名:
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(()) }Run