Skip to content

Commit 8569ef2

Browse files
committed
doc: add example for std::net::lookup_addr
1 parent ac0e845 commit 8569ef2

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

0 commit comments

Comments
 (0)