Skip to content

Instantly share code, notes, and snippets.

@saghm
Last active January 2, 2020 19:54
Show Gist options
  • Save saghm/dfac14987fe01d3705e89de602f9709e to your computer and use it in GitHub Desktop.
Save saghm/dfac14987fe01d3705e89de602f9709e to your computer and use it in GitHub Desktop.
#[cfg(all(feature = "tokio-runtime", feature = "async-std-runtime"))]
compile_error!(
"exactly one of the `tokio-runtime` and `async-std-runtime` features must be chosen"
);
#[cfg(all(not(feature = "tokio-runtime"), not(feature = "async-std-runtime")))]
compile_error!(
"exactly one of the `tokio-runtime` and `async-std-runtime` features must be chosen"
);
use std::future::Future;
use mongodb::{error::Result, options::StreamAddress};
trait AsyncRuntimeHandle {
type AsyncRead;
type AsyncWrite;
type Mutex;
type MutexGuard;
type TcpStream: AsyncRead + AsyncWrite;
type ToSocketAddrs;
fn new() -> Self;
fn tcp_stream_new(
addresses: impl IntoIterator<Item = StreamAddress>,
) -> Result<Self::TcpStream>;
fn spawn_task<F, H, T>(future: F) -> H
where
H: Future<Output = T>,
F: Future<Output = T> + Send + 'static,
T: Send + 'static;
}
#[cfg(feature = "async-std-runtime")]
mod async_std;
#[cfg(feature = "tokio-runtime")]
mod tokio;
#[cfg(feature = "async-std-runtime")]
use async_std::AsyncRuntime;
#[cfg(feature = "tokio-runtime")]
use tokio::AsyncRuntime;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment