tokio_websockets/
resolver.rs1use std::{future::Future, net::SocketAddr};
4
5use crate::Error;
6
7pub trait Resolver: Send {
9 fn resolve(
11 &self,
12 host: &str,
13 port: u16,
14 ) -> impl Future<Output = Result<SocketAddr, Error>> + Send;
15}
16
17pub struct Gai;
20
21impl Resolver for Gai {
22 async fn resolve(&self, host: &str, port: u16) -> Result<SocketAddr, Error> {
23 let host = host.to_owned();
24
25 tokio::net::lookup_host((host, port))
26 .await
27 .map_err(|_| Error::CannotResolveHost)?
28 .next()
29 .ok_or(Error::CannotResolveHost)
30 }
31}