about summary refs log tree commit diff
path: root/src/libstd/net
diff options
context:
space:
mode:
authorTshepang Lekhonkhobe <tshepang@gmail.com>2015-12-03 21:09:21 +0200
committerTshepang Lekhonkhobe <tshepang@gmail.com>2015-12-06 22:12:38 +0200
commit8569ef25913f7ed2410e348eced31e48c04258b7 (patch)
tree59c2be51da8ab286a34b6f8b5e5c44711b945cab /src/libstd/net
parentac0e84522437331f9a06d04a5842acf0234cc86e (diff)
downloadrust-8569ef25913f7ed2410e348eced31e48c04258b7.tar.gz
rust-8569ef25913f7ed2410e348eced31e48c04258b7.zip
doc: add example for std::net::lookup_addr
Diffstat (limited to 'src/libstd/net')
-rw-r--r--src/libstd/net/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libstd/net/mod.rs b/src/libstd/net/mod.rs
index 383dce737f5..83a976c42c6 100644
--- a/src/libstd/net/mod.rs
+++ b/src/libstd/net/mod.rs
@@ -134,6 +134,22 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> {
 /// This function may perform a DNS query to resolve `addr` and may also inspect
 /// system configuration to resolve the specified address. If the address
 /// cannot be resolved, it is returned in string format.
+///
+/// # Examples
+///
+/// ```no_run
+/// #![feature(lookup_addr)]
+/// #![feature(ip_addr)]
+///
+/// use std::net::{self, Ipv4Addr, IpAddr};
+///
+/// let ip_addr = "8.8.8.8";
+/// let addr: Ipv4Addr = ip_addr.parse().unwrap();
+/// let hostname = net::lookup_addr(&IpAddr::V4(addr)).unwrap();
+///
+/// println!("{} --> {}", ip_addr, hostname);
+/// // Output: 8.8.8.8 --> google-public-dns-a.google.com
+/// ```
 #[unstable(feature = "lookup_addr", reason = "recent addition",
            issue = "27705")]
 pub fn lookup_addr(addr: &IpAddr) -> io::Result<String> {