From 4fd0d6b4951b08a20d5378bca75561109dc6d036 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 18 Sep 2023 22:35:58 +0200 Subject: refactor!: make the async DI container not inside a Arc BREAKING CHANGE: The async DI container is no longer inside of a Arc. This affects AsyncBindingBuilder, AsyncBindingScopeConfigurator, AsyncBindingWhenConfigurator & AsyncInjectable --- src/private/castable_factory/threadsafe.rs | 22 ++++++++++------------ src/private/factory.rs | 5 +---- 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'src/private') diff --git a/src/private/castable_factory/threadsafe.rs b/src/private/castable_factory/threadsafe.rs index 6e608b1..6e8da42 100644 --- a/src/private/castable_factory/threadsafe.rs +++ b/src/private/castable_factory/threadsafe.rs @@ -1,6 +1,5 @@ use std::any::type_name; use std::fmt::Debug; -use std::sync::Arc; use crate::private::any_factory::{AnyFactory, AnyThreadsafeFactory}; use crate::private::factory::IThreadsafeFactory; @@ -11,9 +10,7 @@ where DIContainerT: 'static, ReturnInterface: 'static + ?Sized, { - func: &'static (dyn Fn(Arc) -> TransientPtr - + Send - + Sync), + func: &'static (dyn Fn(&DIContainerT) -> TransientPtr + Send + Sync), } impl @@ -23,7 +20,7 @@ where ReturnInterface: 'static + ?Sized, { pub fn new( - func: &'static (dyn Fn<(Arc,), Output = TransientPtr> + func: &'static (dyn Fn(&DIContainerT) -> TransientPtr + Send + Sync), ) -> Self @@ -38,7 +35,7 @@ where DIContainerT: 'static, ReturnInterface: 'static + ?Sized, { - fn call(&self, di_container: Arc) -> TransientPtr + fn call(&self, di_container: &DIContainerT) -> TransientPtr { (self.func)(di_container) } @@ -72,7 +69,7 @@ where let ret = type_name::>(); formatter.write_fmt(format_args!( - "ThreadsafeCastableFactory (Arc) -> {ret} {{ ... }}", + "ThreadsafeCastableFactory (&AsyncDIContainer) -> {ret} {{ ... }}", )) } } @@ -92,13 +89,14 @@ mod tests #[test] fn can_call() { - let castable_factory = ThreadsafeCastableFactory::new(&|_| { - TransientPtr::new(Bacon { heal_amount: 27 }) - }); + let castable_factory = + ThreadsafeCastableFactory::new(&|_: &MockAsyncDIContainer| { + TransientPtr::new(Bacon { heal_amount: 27 }) + }); - let mock_di_container = Arc::new(MockAsyncDIContainer::new()); + let mock_di_container = MockAsyncDIContainer::new(); - let output = castable_factory.call(mock_di_container); + let output = castable_factory.call(&mock_di_container); assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 27 })); } diff --git a/src/private/factory.rs b/src/private/factory.rs index c1672e1..7191c2c 100644 --- a/src/private/factory.rs +++ b/src/private/factory.rs @@ -1,6 +1,3 @@ -#[cfg(feature = "async")] -use std::sync::Arc; - use crate::private::cast::CastFrom; use crate::ptr::TransientPtr; @@ -19,5 +16,5 @@ pub trait IThreadsafeFactory: where ReturnInterface: 'static + ?Sized, { - fn call(&self, di_container: Arc) -> TransientPtr; + fn call(&self, di_container: &DIContainerT) -> TransientPtr; } -- cgit v1.2.3-18-g5258