use std::{future::Future, time::Duration}; use tokio::{io, time}; // Wraps a future in a tokio timeout call, transforming the error into // an io error pub async fn timeout(d: Duration, f: F) -> io::Result where F: Future, { time::timeout(d, f) .await .map_err(|x| io::Error::new(io::ErrorKind::TimedOut, x)) }