Struct SocketAddr

pub struct SocketAddr { pub(in ::os::windows::net) len: u32 }

Fields

len: u32

Implementations

impl SocketAddr

fn as_pathname(&self) -> Option<&Path>

Returns the contents of this address if it is a pathname address.

Examples

With a pathname:

#![feature(windows_unix_domain_sockets)]
use std::os::windows::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(())
}
fn from_pathname<P>(path: P) -> Result<SocketAddr>
where
    P: AsRef<Path>,

Constructs a SockAddr with the family AF_UNIX and the provided path.

Errors

Returns an error if the path is longer than SUN_LEN or if it contains NULL bytes.

Examples

#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::SocketAddr;
use std::path::Path;

# fn main() -> std::io::Result<()> {
let address = SocketAddr::from_pathname("/path/to/socket")?;
assert_eq!(address.as_pathname(), Some(Path::new("/path/to/socket")));
# Ok(())
# }

Creating a SocketAddr with a NULL byte results in an error.

#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::SocketAddr;

assert!(SocketAddr::from_pathname("/path/with/\0/bytes").is_err());
fn address(&self) -> AddressKind<'_>
fn is_unnamed(&self) -> bool

Returns true if the address is unnamed.

Examples

A named address:

#![feature(windows_unix_domain_sockets)]
use std::os::windows::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(())
}

Trait Implementations

impl Debug for SocketAddr

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl Freeze for SocketAddr

impl RefUnwindSafe for SocketAddr

impl Send for SocketAddr

impl Sync for SocketAddr

impl Unpin for SocketAddr

impl UnsafeUnpin for SocketAddr

impl UnwindSafe for SocketAddr

Blanket Implementations

impl<T> Any for SocketAddr where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for SocketAddr where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for SocketAddr where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for SocketAddr

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for SocketAddr where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for SocketAddr

impl<T, U> Into<U> for SocketAddr where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for SocketAddr where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for SocketAddr where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>