use std::future::Future;
use std::io;
use std::net::SocketAddr;
#[cfg(unix)]
use std::path::Path;
use std::time::Duration;
#[deprecated(
since = "0.2.0",
note = "Use `RuntimeCompletion` or `RuntimePoll` instead. Will be removed in 0.3.0."
)]
#[allow(async_fn_in_trait)]
pub trait Runtime: Send + Sync + 'static {
type TcpStream: hyper::rt::Read + hyper::rt::Write + Send + Unpin + 'static;
type Sleep: Future<Output = ()> + Send + Sync;
fn connect(addr: SocketAddr) -> impl Future<Output = io::Result<Self::TcpStream>> + Send;
async fn resolve(host: &str, port: u16) -> io::Result<SocketAddr> {
let addrs = Self::resolve_all(host, port).await?;
addrs
.into_iter()
.next()
.ok_or_else(|| io::Error::new(io::ErrorKind::AddrNotAvailable, "no addresses resolved"))
}
fn resolve_all(
host: &str,
port: u16,
) -> impl Future<Output = io::Result<Vec<SocketAddr>>> + Send;
fn sleep(duration: Duration) -> Self::Sleep;
fn spawn<F>(future: F)
where
F: Future<Output = ()> + Send + 'static;
fn set_tcp_keepalive(
_stream: &Self::TcpStream,
_time: Duration,
_interval: Option<Duration>,
_retries: Option<u32>,
) -> io::Result<()> {
Ok(())
}
fn set_tcp_fast_open(_stream: &Self::TcpStream) -> io::Result<()> {
Ok(())
}
#[cfg(target_os = "linux")]
fn bind_device(_stream: &Self::TcpStream, _interface: &str) -> io::Result<()> {
Err(io::Error::new(
io::ErrorKind::Unsupported,
"interface binding not supported by this runtime",
))
}
fn from_std_tcp(stream: std::net::TcpStream) -> io::Result<Self::TcpStream>;
fn connect_bound(
addr: SocketAddr,
local: std::net::IpAddr,
) -> impl Future<Output = io::Result<Self::TcpStream>> + Send;
#[cfg(unix)]
type UnixStream: hyper::rt::Read + hyper::rt::Write + Send + Unpin + 'static;
#[cfg(unix)]
fn connect_unix(path: &Path) -> impl Future<Output = io::Result<Self::UnixStream>> + Send;
}