From a1ddd1bc6e1af0d98b87126d3e86da30bc1d3f1c Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 17 Sep 2023 13:32:06 +0200 Subject: refactor!: make the blocking DI container not inside a Rc BREAKING CHANGE: The blocking DI container is no longer inside of a Rc. This affects BindingBuilder, BindingScopeConfigurator, BindingWhenConfigurator & Injectable --- src/private/castable_factory/blocking.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/private/castable_factory') diff --git a/src/private/castable_factory/blocking.rs b/src/private/castable_factory/blocking.rs index 0761b7e..a28ce71 100644 --- a/src/private/castable_factory/blocking.rs +++ b/src/private/castable_factory/blocking.rs @@ -1,6 +1,5 @@ use std::any::type_name; use std::fmt::Debug; -use std::rc::Rc; use crate::private::any_factory::AnyFactory; use crate::private::factory::IFactory; @@ -11,7 +10,7 @@ where ReturnInterface: 'static + ?Sized, DIContainerT: 'static, { - func: &'static dyn Fn<(Rc,), Output = TransientPtr>, + func: &'static dyn Fn(&DIContainerT) -> TransientPtr, } impl CastableFactory @@ -19,10 +18,7 @@ where ReturnInterface: 'static + ?Sized, { pub fn new( - func: &'static dyn Fn< - (Rc,), - Output = TransientPtr, - >, + func: &'static dyn Fn(&DIContainerT) -> TransientPtr, ) -> Self { Self { func } @@ -34,7 +30,7 @@ impl IFactory where ReturnInterface: 'static + ?Sized, { - fn call(&self, di_container: Rc) -> TransientPtr + fn call(&self, di_container: &DIContainerT) -> TransientPtr { (self.func)(di_container) } @@ -58,7 +54,9 @@ where { let ret = type_name::>(); - formatter.write_fmt(format_args!("CastableFactory (Rc) -> {ret}")) + formatter.write_fmt(format_args!( + "CastableFactory (&DIContainer) -> {ret} {{ ... }}" + )) } } @@ -77,12 +75,13 @@ mod tests #[test] fn can_call() { - let castable_factory = - CastableFactory::new(&|_| TransientPtr::new(Bacon { heal_amount: 27 })); + let castable_factory = CastableFactory::new(&|_: &MockDIContainer| { + TransientPtr::new(Bacon { heal_amount: 27 }) + }); - let mock_di_container = Rc::new(MockDIContainer::new()); + let mock_di_container = MockDIContainer::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 })); } -- cgit v1.2.3-18-g5258