From f27e98125929e5d76142aa321b735be0e97ff4cd Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Thu, 23 Feb 2023 22:32:08 +0100 Subject: [PATCH] Add workaround for tokio-rs/tokio#5502 --- src/setup/core.rs | 27 +++++++++++++++++++++++++++ src/setup/mod.rs | 2 +- src/setup/setup.rs | 16 +++++++++------- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/setup/core.rs b/src/setup/core.rs index 4a640ea..1bab2db 100644 --- a/src/setup/core.rs +++ b/src/setup/core.rs @@ -20,6 +20,17 @@ pub trait AddGeneric { } macro_rules! add_generic { + // Workaround for https://github.com/tokio-rs/tokio/issues/5502 + () => ( + #[async_trait(?Send)] + impl AddGeneric<()> for Setup + { + async fn add_generic(&self, (): ()) -> Result<(StoringLogger, (), bool), (StoringLogger, Box)> + { + Ok((StoringLogger::default(), (), false)) + } + } + ); ( $($name:ident)* ) => ( #[async_trait(?Send)] #[allow(non_snake_case)] @@ -202,3 +213,19 @@ impl SymbolRunner for RegularSetupCore { result } } + +#[cfg(test)] +mod test { + use super::super::setup::Setup; + use super::AddGeneric; + use crate::async_utils::run; + use crate::DrySymbolRunner; + + #[test] + fn empty() { + let setup: Setup<_, (), (), (), ()> = Setup::new(DrySymbolRunner); + run(async { + assert!(setup.add_generic(()).await.is_ok()); + }) + } +} diff --git a/src/setup/mod.rs b/src/setup/mod.rs index a6873c8..6392610 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -1,6 +1,6 @@ mod core; -mod util; mod symbol_runner; +mod util; pub use symbol_runner::{ DelayingSymbolRunner, DrySymbolRunner, InitializingSymbolRunner, ReportingSymbolRunner, SymbolRunner, diff --git a/src/setup/setup.rs b/src/setup/setup.rs index 6d06eef..414259d 100644 --- a/src/setup/setup.rs +++ b/src/setup/setup.rs @@ -27,6 +27,14 @@ struct SetupInner { #[derive(Debug)] pub struct Setup(Rc, Rs, As>>); +impl Setup { + pub fn new(symbol_runner: SR) -> Self { + Self(Rc::new(SetupInner { + core: RegularSetupCore::new(symbol_runner), + resources: RefCell::default(), + })) + } +} impl Setup { @@ -111,13 +119,7 @@ impl SetupFacade { impl SetupFacade { pub fn new_with(symbol_runner: SR, logger: LOG) -> Self { - Self( - logger, - Setup(Rc::new(SetupInner { - core: RegularSetupCore::new(symbol_runner), - resources: RefCell::default(), - })), - ) + Self(logger, Setup::new(symbol_runner)) } }