aboutsummaryrefslogtreecommitdiff
path: root/src/private
diff options
context:
space:
mode:
Diffstat (limited to 'src/private')
-rw-r--r--src/private/castable_factory/blocking.rs63
-rw-r--r--src/private/factory.rs4
2 files changed, 5 insertions, 62 deletions
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<ReturnInterface, DIContainerT> IFactory<ReturnInterface, DIContainerT>
where
ReturnInterface: 'static + ?Sized,
{
-}
-
-impl<ReturnInterface, DIContainerT> Fn<(Rc<DIContainerT>,)>
- for CastableFactory<ReturnInterface, DIContainerT>
-where
- ReturnInterface: 'static + ?Sized,
-{
- extern "rust-call" fn call(&self, args: (Rc<DIContainerT>,)) -> Self::Output
- {
- self.func.call(args)
- }
-}
-
-impl<ReturnInterface, DIContainerT> FnMut<(Rc<DIContainerT>,)>
- for CastableFactory<ReturnInterface, DIContainerT>
-where
- ReturnInterface: 'static + ?Sized,
-{
- extern "rust-call" fn call_mut(&mut self, args: (Rc<DIContainerT>,)) -> Self::Output
- {
- self.call(args)
- }
-}
-
-impl<ReturnInterface, DIContainerT> FnOnce<(Rc<DIContainerT>,)>
- for CastableFactory<ReturnInterface, DIContainerT>
-where
- ReturnInterface: 'static + ?Sized,
-{
- type Output = TransientPtr<ReturnInterface>;
-
- extern "rust-call" fn call_once(self, args: (Rc<DIContainerT>,)) -> Self::Output
+ fn call(&self, di_container: Rc<DIContainerT>) -> TransientPtr<ReturnInterface>
{
- 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 }));
- }
}
diff --git a/src/private/factory.rs b/src/private/factory.rs
index af6df8a..23b4e8f 100644
--- a/src/private/factory.rs
+++ b/src/private/factory.rs
@@ -4,11 +4,11 @@ use crate::private::cast::CastFrom;
use crate::ptr::TransientPtr;
/// Interface for a factory.
-pub trait IFactory<ReturnInterface, DIContainerT>:
- Fn<(Rc<DIContainerT>,), Output = TransientPtr<ReturnInterface>> + CastFrom
+pub trait IFactory<ReturnInterface, DIContainerT>: CastFrom
where
ReturnInterface: 'static + ?Sized,
{
+ fn call(&self, di_container: Rc<DIContainerT>) -> TransientPtr<ReturnInterface>;
}
/// Interface for a threadsafe factory.