Skip to content

Commit 7b77f67

Browse files
committed
Auto merge of #30188 - tshepang:lookup_addr-example, r=alexcrichton
2 parents e819d8a + 8569ef2 commit 7b77f67

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libstd/net/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ pub fn lookup_host(host: &str) -> io::Result<LookupHost> {
135135
/// This function may perform a DNS query to resolve `addr` and may also inspect
136136
/// system configuration to resolve the specified address. If the address
137137
/// cannot be resolved, it is returned in string format.
138+
///
139+
/// # Examples
140+
///
141+
/// ```no_run
142+
/// #![feature(lookup_addr)]
143+
/// #![feature(ip_addr)]
144+
///
145+
/// use std::net::{self, Ipv4Addr, IpAddr};
146+
///
147+
/// let ip_addr = "8.8.8.8";
148+
/// let addr: Ipv4Addr = ip_addr.parse().unwrap();
149+
/// let hostname = net::lookup_addr(&IpAddr::V4(addr)).unwrap();
150+
///
151+
/// println!("{} --> {}", ip_addr, hostname);
152+
/// // Output: 8.8.8.8 --> google-public-dns-a.google.com
153+
/// ```
138154
#[unstable(feature = "lookup_addr", reason = "recent addition",
139155
issue = "27705")]
140156
#[rustc_deprecated(reason = "ipaddr type is being deprecated",

0 commit comments

Comments
 (0)