use std::future::Future;
pub trait AsyncTest: 'static + Future<Output = Result<(), String>> {}
impl<F> AsyncTest for F where F: 'static + Future<Output = Result<(), String>> {}
pub trait IntoFut<M> {
fn into_fut(self) -> impl AsyncTest;
}
pub struct ReturnsResult;
pub struct ReturnsUnit;
pub struct ReturnsNever;
impl<T> IntoFut<ReturnsResult> for T
where
T: AsyncTest,
{
fn into_fut(self) -> impl AsyncTest { self }
}
impl<T> IntoFut<ReturnsUnit> for T
where
T: 'static + Future<Output = ()>,
{
fn into_fut(self) -> impl AsyncTest {
async move {
self.await;
Ok(())
}
}
}
impl<T> IntoFut<ReturnsNever> for T
where
T: 'static + Future<Output = !>,
{
fn into_fut(self) -> impl AsyncTest {
async move {
self.await;
}
}
}
#[track_caller]
pub fn block_on_async_test<M>(fut: impl IntoFut<M>) {
futures_lite::future::block_on(fut.into_fut()).unwrap();
}