]> git.lizzy.rs Git - rust.git/commitdiff
doc: add example for std::net::lookup_addr
authorTshepang Lekhonkhobe <tshepang@gmail.com>
Thu, 3 Dec 2015 19:09:21 +0000 (21:09 +0200)
committerTshepang Lekhonkhobe <tshepang@gmail.com>
Sun, 6 Dec 2015 20:12:38 +0000 (22:12 +0200)
src/libstd/net/mod.rs

index 383dce737f511142b75860d579765bafe56505e9..83a976c42c6ae0bc04634dc89782069b945bea27 100644 (file)
@@ -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> {