From 3e3a853615e97ee7c3aef09736eae8170c6fd78e Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 17 Sep 2023 13:08:23 +0200 Subject: refactor: replace castable factory Fn impl with method --- src/private/castable_factory/blocking.rs | 63 ++------------------------------ 1 file changed, 3 insertions(+), 60 deletions(-) (limited to 'src/private/castable_factory') diff --git a/src/private/castable_factory/blocking.rs b/src/private/castable_factory/blocking.rs index 24c653e..0761b7e 100644 --- a/src/private/castable_factory/blocking.rs +++ b/src/private/castable_factory/blocking.rs @@ -34,40 +34,9 @@ impl IFactory where ReturnInterface: 'static + ?Sized, { -} - -impl Fn<(Rc,)> - for CastableFactory -where - ReturnInterface: 'static + ?Sized, -{ - extern "rust-call" fn call(&self, args: (Rc,)) -> Self::Output - { - self.func.call(args) - } -} - -impl FnMut<(Rc,)> - for CastableFactory -where - ReturnInterface: 'static + ?Sized, -{ - extern "rust-call" fn call_mut(&mut self, args: (Rc,)) -> Self::Output - { - self.call(args) - } -} - -impl FnOnce<(Rc,)> - for CastableFactory -where - ReturnInterface: 'static + ?Sized, -{ - type Output = TransientPtr; - - extern "rust-call" fn call_once(self, args: (Rc,)) -> Self::Output + fn call(&self, di_container: Rc) -> TransientPtr { - self.call(args) + (self.func)(di_container) } } @@ -113,34 +82,8 @@ mod tests let mock_di_container = Rc::new(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 })); } - - #[test] - fn can_call_mut() - { - let mut castable_factory = - CastableFactory::new(&|_| TransientPtr::new(Bacon { heal_amount: 103 })); - - let mock_di_container = Rc::new(MockDIContainer::new()); - - let output = castable_factory.call_mut((mock_di_container,)); - - assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 103 })); - } - - #[test] - fn can_call_once() - { - let castable_factory = - CastableFactory::new(&|_| TransientPtr::new(Bacon { heal_amount: 19 })); - - let mock_di_container = Rc::new(MockDIContainer::new()); - - let output = castable_factory.call_once((mock_di_container,)); - - assert_eq!(output, TransientPtr::new(Bacon { heal_amount: 19 })); - } } -- cgit v1.2.3-18-g5258