1cfg_net! {
2 use crate::net::addr::{self, ToSocketAddrs};
3
4 use std::io;
5 use std::net::SocketAddr;
6
7 /// Performs a DNS resolution.
8 ///
9 /// The returned iterator may not actually yield any values depending on the
10 /// outcome of any resolution performed.
11 ///
12 /// This API is not intended to cover all DNS use cases. Anything beyond the
13 /// basic use case should be done with a specialized library.
14 ///
15 /// # Examples
16 ///
17 /// To resolve a DNS entry:
18 ///
19 /// ```no_run
20 /// use tokio::net;
21 /// use std::io;
22 ///
23 /// #[tokio::main]
24 /// async fn main() -> io::Result<()> {
25 /// for addr in net::lookup_host("localhost:3000").await? {
26 /// println!("socket address is {}", addr);
27 /// }
28 ///
29 /// Ok(())
30 /// }
31 /// ```
32 pub async fn lookup_host<T>(host: T) -> io::Result<impl Iterator<Item = SocketAddr>>
33 where
34 T: ToSocketAddrs
35 {
36 addr::to_socket_addrs(host).await
37 }
38}
39