diff options
author | HampusM <hampus@hampusmat.com> | 2023-08-15 23:15:19 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-08-15 23:18:59 +0200 |
commit | e381ae3b8649de47ba46925e402946658ac16d20 (patch) | |
tree | 32ecc7e4592f25d43dc1e76399d3fffae3272e1e /src/di_container/blocking | |
parent | 9423d67efb161d9a94a7ab6c5899c6bc7ecaee7c (diff) |
fix!: make the factory macro not change its input
BREAKING CHANGE: The factory macro no longer
- Changes the return type to be inside of a TransientPtr
- Adds Send + Sync bounds when the threadsafe or the async flag is set
- Changes the return type be inside of a BoxFuture when the async flag is set
Diffstat (limited to 'src/di_container/blocking')
-rw-r--r-- | src/di_container/blocking/binding/builder.rs | 7 | ||||
-rw-r--r-- | src/di_container/blocking/mod.rs | 48 |
2 files changed, 22 insertions, 33 deletions
diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index 991961c..91855f5 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -151,10 +151,10 @@ where /// # impl ICustomer for Customer {} /// # /// # #[factory] - /// # type ICustomerFactory = dyn Fn(String, u32) -> dyn ICustomer; + /// # type ICustomerFactory = dyn Fn(String, u32) -> TransientPtr<dyn ICustomer>; /// # /// # #[factory] - /// # type ICustomerIDFactory = dyn Fn(u32) -> dyn ICustomerID; + /// # type ICustomerIDFactory = dyn Fn(u32) -> TransientPtr<dyn ICustomerID>; /// # /// # fn main() -> Result<(), Box<dyn Error>> /// # { @@ -354,7 +354,8 @@ mod tests use crate::ptr::TransientPtr; #[factory] - type IUserManagerFactory = dyn Fn(i32, String) -> dyn subjects::IUserManager; + type IUserManagerFactory = + dyn Fn(i32, String) -> TransientPtr<dyn subjects::IUserManager>; let mut mock_di_container = mocks::blocking_di_container::MockDIContainer::new(); diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs index 5781583..aa89aad 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking/mod.rs @@ -493,28 +493,22 @@ mod tests } } - type FactoryFunc = dyn Fn< - (std::rc::Rc<DIContainer>,), - Output = Box< - dyn Fn<(Vec<i128>,), Output = crate::ptr::TransientPtr<dyn IUserManager>>, - >, - >; - use crate as syrette; #[crate::factory] - type IUserManagerFactory = dyn Fn(Vec<i128>) -> dyn IUserManager; + type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager>; let di_container = DIContainer::new(); - let factory_func: &'static FactoryFunc = &|_: Rc<DIContainer>| { - Box::new(move |users| { - let user_manager: TransientPtr<dyn IUserManager> = - TransientPtr::new(UserManager::new(users)); + let factory_func: &dyn Fn(Rc<DIContainer>) -> Box<IUserManagerFactory> = + &|_: Rc<DIContainer>| { + Box::new(move |users| { + let user_manager: TransientPtr<dyn IUserManager> = + TransientPtr::new(UserManager::new(users)); - user_manager - }) - }; + user_manager + }) + }; let mut mock_provider = mocks::blocking_provider::MockProvider::new(); @@ -577,28 +571,22 @@ mod tests } } - type FactoryFunc = dyn Fn< - (std::rc::Rc<DIContainer>,), - Output = Box< - dyn Fn<(Vec<i128>,), Output = crate::ptr::TransientPtr<dyn IUserManager>>, - >, - >; - use crate as syrette; #[crate::factory] - type IUserManagerFactory = dyn Fn(Vec<i128>) -> dyn IUserManager; + type IUserManagerFactory = dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager>; let di_container = DIContainer::new(); - let factory_func: &'static FactoryFunc = &|_: Rc<DIContainer>| { - Box::new(move |users| { - let user_manager: TransientPtr<dyn IUserManager> = - TransientPtr::new(UserManager::new(users)); + let factory_func: &dyn Fn(Rc<DIContainer>) -> Box<IUserManagerFactory> = + &|_: Rc<DIContainer>| { + Box::new(move |users| { + let user_manager: TransientPtr<dyn IUserManager> = + TransientPtr::new(UserManager::new(users)); - user_manager - }) - }; + user_manager + }) + }; let mut mock_provider = mocks::blocking_provider::MockProvider::new(); |