@@ -85,6 +85,21 @@ enum AddressKind<'a> {
85
85
}
86
86
87
87
/// An address associated with a Unix socket.
88
+ ///
89
+ /// # Examples
90
+ ///
91
+ /// ```
92
+ /// use std::os::unix::net::UnixListener;
93
+ ///
94
+ /// let socket = match UnixListener::bind("/tmp/sock") {
95
+ /// Ok(sock) => sock,
96
+ /// Err(e) => {
97
+ /// println!("Couldn't bind: {:?}", e);
98
+ /// return
99
+ /// }
100
+ /// };
101
+ /// let addr = socket.local_addr().expect("Couldn't get local address");
102
+ /// ```
88
103
#[ derive( Clone ) ]
89
104
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
90
105
pub struct SocketAddr {
@@ -121,6 +136,16 @@ impl SocketAddr {
121
136
}
122
137
123
138
/// Returns true if and only if the address is unnamed.
139
+ ///
140
+ /// # Examples
141
+ ///
142
+ /// ```
143
+ /// use std::os::unix::net::UnixListener;
144
+ ///
145
+ /// let socket = match UnixListener::bind("/tmp/sock").unwrap();
146
+ /// let addr = socket.local_addr().expect("Couldn't get local address");
147
+ /// assert_eq!(addr.is_unnamed(), false);
148
+ /// ```
124
149
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
125
150
pub fn is_unnamed ( & self ) -> bool {
126
151
if let AddressKind :: Unnamed = self . address ( ) {
@@ -131,6 +156,17 @@ impl SocketAddr {
131
156
}
132
157
133
158
/// Returns the contents of this address if it is a `pathname` address.
159
+ ///
160
+ /// # Examples
161
+ ///
162
+ /// ```
163
+ /// use std::os::unix::net::UnixListener;
164
+ /// use std::path::Path;
165
+ ///
166
+ /// let socket = match UnixListener::bind("/tmp/sock").unwrap();
167
+ /// let addr = socket.local_addr().expect("Couldn't get local address");
168
+ /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock")));
169
+ /// ```
134
170
#[ stable( feature = "unix_socket" , since = "1.10.0" ) ]
135
171
pub fn as_pathname ( & self ) -> Option < & Path > {
136
172
if let AddressKind :: Pathname ( path) = self . address ( ) {
0 commit comments