async_rs/traits/
addr.rs

1use std::{future, io, net::SocketAddr};
2
3/// A common interface for resolving domain name + port to `SocketAddr`
4pub trait AsyncToSocketAddrs {
5    /// Resolve the domain name through DNS and return an `Iterator` of `SocketAddr`
6    fn to_socket_addrs(
7        self,
8    ) -> impl Future<Output = io::Result<impl Iterator<Item = SocketAddr> + Send + 'static>>
9    + Send
10    + 'static
11    where
12        Self: Sized;
13}
14
15impl<A: Into<SocketAddr>> AsyncToSocketAddrs for A {
16    fn to_socket_addrs(
17        self,
18    ) -> impl Future<Output = io::Result<impl Iterator<Item = SocketAddr> + Send + 'static>>
19    + Send
20    + 'static {
21        future::ready(Ok(Some(self.into()).into_iter()))
22    }
23}