From e381ae3b8649de47ba46925e402946658ac16d20 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 15 Aug 2023 23:15:19 +0200 Subject: 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 --- src/di_container/asynchronous/binding/builder.rs | 25 +++++++++++++++++------- src/di_container/asynchronous/mod.rs | 6 ++++-- 2 files changed, 22 insertions(+), 9 deletions(-) (limited to 'src/di_container/asynchronous') 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 + Send + Sync; /// # /// # #[tokio::main] /// # async fn main() -> Result<(), Box> @@ -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 + /// # > + Send + Sync; /// # /// # #[tokio::main] /// # async fn main() -> Result<(), Box> @@ -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 + + 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> { + 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 + > + 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) -> dyn IUserManager; + type IUserManagerFactory = + dyn Fn(Vec) -> TransientPtr + 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) -> dyn IUserManager; + type IUserManagerFactory = + dyn Fn(Vec) -> TransientPtr + Send + Sync; let di_container = AsyncDIContainer::new(); -- cgit v1.2.3-18-g5258