async_std/os/unix/net/mod.rs
1//! Unix-specific networking extensions.
2
3pub use datagram::UnixDatagram;
4pub use listener::{Incoming, UnixListener};
5pub use stream::UnixStream;
6
7mod datagram;
8mod listener;
9mod stream;
10
11cfg_not_docs! {
12 pub use std::os::unix::net::SocketAddr;
13}
14
15cfg_docs! {
16 use std::fmt;
17
18 use crate::path::Path;
19
20 /// An address associated with a Unix socket.
21 ///
22 /// # Examples
23 ///
24 /// ```
25 /// use async_std::os::unix::net::UnixListener;
26 ///
27 /// let socket = UnixListener::bind("/tmp/socket").await?;
28 /// let addr = socket.local_addr()?;
29 /// ```
30 #[derive(Clone)]
31 pub struct SocketAddr {
32 _private: (),
33 }
34
35 impl SocketAddr {
36 /// Returns `true` if the address is unnamed.
37 ///
38 /// # Examples
39 ///
40 /// A named address:
41 ///
42 /// ```no_run
43 /// use async_std::os::unix::net::UnixListener;
44 ///
45 /// let socket = UnixListener::bind("/tmp/socket").await?;
46 /// let addr = socket.local_addr()?;
47 /// assert_eq!(addr.is_unnamed(), false);
48 /// ```
49 ///
50 /// An unnamed address:
51 ///
52 /// ```no_run
53 /// use async_std::os::unix::net::UnixDatagram;
54 ///
55 /// let socket = UnixDatagram::unbound().await?;
56 /// let addr = socket.local_addr()?;
57 /// assert_eq!(addr.is_unnamed(), true);
58 /// ```
59 pub fn is_unnamed(&self) -> bool {
60 unreachable!("this impl only appears in the rendered docs")
61 }
62
63 /// Returns the contents of this address if it is a `pathname` address.
64 ///
65 /// # Examples
66 ///
67 /// With a pathname:
68 ///
69 /// ```no_run
70 /// use async_std::os::unix::net::UnixListener;
71 /// use async_std::path::Path;
72 ///
73 /// let socket = UnixListener::bind("/tmp/socket").await?;
74 /// let addr = socket.local_addr()?;
75 /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/socket")));
76 /// ```
77 ///
78 /// Without a pathname:
79 ///
80 /// ```
81 /// use async_std::os::unix::net::UnixDatagram;
82 ///
83 /// let socket = UnixDatagram::unbound()?;
84 /// let addr = socket.local_addr()?;
85 /// assert_eq!(addr.as_pathname(), None);
86 /// ```
87 pub fn as_pathname(&self) -> Option<&Path> {
88 unreachable!("this impl only appears in the rendered docs")
89 }
90 }
91
92 impl fmt::Debug for SocketAddr {
93 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
94 unreachable!("this impl only appears in the rendered docs")
95 }
96 }
97}