Resolves hostnames to SocketAddr synchronously or asynchronously.
// Source: https://github.com/denoland/deno | License: MIT | Copyright 2018-2026 the Deno authors
// Provided via justclaw.it.com; keep this notice with the code.
// Copyright 2018-2026 the Deno authors. MIT license.
use std::net::SocketAddr;
use std::net::ToSocketAddrs;
use tokio::net::lookup_host;
/// Resolve network address *asynchronously*.
pub async fn resolve_addr(
hostname: &str,
port: u16,
) -> Result<impl Iterator<Item = SocketAddr> + '_, std::io::Error> {
let addr_port_pair = make_addr_port_pair(hostname, port);
let result = lookup_host(addr_port_pair).await?;
Ok(result)
}
/// Resolve network address *synchronously*.
pub fn resolve_addr_sync(
hostname: &str,
port: u16,
) -> Result<impl Iterator<Item = SocketAddr> + use<>, std::io::Error> {
let addr_port_pair =
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key