diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-12-07 16:20:53 -0800 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-12-08 09:38:43 -0800 |
| commit | 9976f5f7c551edb557b0f4633dfcd772cf040a2b (patch) | |
| tree | 39256a17a0a331e2cb2e64c83aede53e07a01a57 /src/libstd/sys | |
| parent | 535b6d397f735ff72064462be38f733d2637cd6f (diff) | |
| download | rust-9976f5f7c551edb557b0f4633dfcd772cf040a2b.tar.gz rust-9976f5f7c551edb557b0f4633dfcd772cf040a2b.zip | |
Add missing doc examples for SocketAddr struct
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/ext/net.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 80f53da1cef..47a803424b5 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -85,6 +85,21 @@ enum AddressKind<'a> { } /// An address associated with a Unix socket. +/// +/// # Examples +/// +/// ``` +/// use std::os::unix::net::UnixListener; +/// +/// let socket = match UnixListener::bind("/tmp/sock") { +/// Ok(sock) => sock, +/// Err(e) => { +/// println!("Couldn't bind: {:?}", e); +/// return +/// } +/// }; +/// let addr = socket.local_addr().expect("Couldn't get local address"); +/// ``` #[derive(Clone)] #[stable(feature = "unix_socket", since = "1.10.0")] pub struct SocketAddr { @@ -121,6 +136,16 @@ impl SocketAddr { } /// Returns true if and only if the address is unnamed. + /// + /// # Examples + /// + /// ``` + /// use std::os::unix::net::UnixListener; + /// + /// let socket = match UnixListener::bind("/tmp/sock").unwrap(); + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.is_unnamed(), false); + /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn is_unnamed(&self) -> bool { if let AddressKind::Unnamed = self.address() { @@ -131,6 +156,17 @@ impl SocketAddr { } /// Returns the contents of this address if it is a `pathname` address. + /// + /// # Examples + /// + /// ``` + /// use std::os::unix::net::UnixListener; + /// use std::path::Path; + /// + /// let socket = match UnixListener::bind("/tmp/sock").unwrap(); + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn as_pathname(&self) -> Option<&Path> { if let AddressKind::Pathname(path) = self.address() { |
