aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/di_container/asynchronous/binding/builder.rs25
-rw-r--r--src/di_container/asynchronous/mod.rs6
-rw-r--r--src/di_container/blocking/binding/builder.rs7
-rw-r--r--src/di_container/blocking/mod.rs48
4 files changed, 44 insertions, 42 deletions
diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs
index 45597e8..306d196 100644
--- a/src/di_container/asynchronous/binding/builder.rs
+++ b/src/di_container/asynchronous/binding/builder.rs
@@ -147,7 +147,7 @@ where
/// # impl Foo for Bar {}
/// #
/// # #[factory(threadsafe = true)]
- /// # type FooFactory = dyn Fn(i32, String) -> dyn Foo;
+ /// # type FooFactory = dyn Fn(i32, String) -> TransientPtr<dyn Foo> + Send + Sync;
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn Error>>
@@ -226,6 +226,7 @@ where
/// # use syrette::{factory};
/// # use syrette::di_container::asynchronous::prelude::*;
/// # use syrette::ptr::TransientPtr;
+ /// # use syrette::future::BoxFuture;
/// #
/// # trait Foo: Send + Sync {}
/// #
@@ -238,7 +239,10 @@ where
/// # impl Foo for Bar {}
/// #
/// # #[factory(async = true)]
- /// # type FooFactory = dyn Fn(i32, String) -> dyn Foo;
+ /// # type FooFactory = dyn Fn(i32, String) -> BoxFuture<
+ /// # 'static,
+ /// # TransientPtr<dyn Foo>
+ /// # > + Send + Sync;
/// #
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn Error>>
@@ -546,10 +550,12 @@ mod tests
#[factory(threadsafe = true)]
type IUserManagerFactory = dyn Fn(
- String,
- i32,
- subjects_async::Number,
- ) -> dyn subjects_async::IUserManager;
+ String,
+ i32,
+ subjects_async::Number,
+ ) -> TransientPtr<dyn subjects_async::IUserManager>
+ + Send
+ + Sync;
let mut di_container_mock =
mocks::async_di_container::MockAsyncDIContainer::new();
@@ -590,12 +596,17 @@ mod tests
#[cfg(feature = "factory")]
async fn can_bind_to_async_factory() -> Result<(), Box<dyn Error>>
{
+ use crate::future::BoxFuture;
use crate::ptr::TransientPtr;
use crate::test_utils::async_closure;
use crate::{self as syrette, factory};
+ #[rustfmt::skip]
#[factory(async = true)]
- type IUserManagerFactory = dyn Fn(String) -> dyn subjects_async::IUserManager;
+ type IUserManagerFactory = dyn Fn(String) -> BoxFuture<
+ 'static,
+ TransientPtr<dyn subjects_async::IUserManager>
+ > + Send + Sync;
let mut di_container_mock =
mocks::async_di_container::MockAsyncDIContainer::new();
diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs
index 927f549..d330f4a 100644
--- a/src/di_container/asynchronous/mod.rs
+++ b/src/di_container/asynchronous/mod.rs
@@ -657,7 +657,8 @@ mod tests
use crate::private::castable_factory::threadsafe::ThreadsafeCastableFactory;
#[crate::factory(threadsafe = true)]
- type IUserManagerFactory = dyn Fn(Vec<i128>) -> dyn IUserManager;
+ type IUserManagerFactory =
+ dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager> + Send + Sync;
let di_container = AsyncDIContainer::new();
@@ -752,7 +753,8 @@ mod tests
use crate::private::castable_factory::threadsafe::ThreadsafeCastableFactory;
#[crate::factory(threadsafe = true)]
- type IUserManagerFactory = dyn Fn(Vec<i128>) -> dyn IUserManager;
+ type IUserManagerFactory =
+ dyn Fn(Vec<i128>) -> TransientPtr<dyn IUserManager> + Send + Sync;
let di_container = AsyncDIContainer::new();
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();