diff options
author | HampusM <hampus@hampusmat.com> | 2024-09-15 23:33:33 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-09-15 23:33:33 +0200 |
commit | d46181de1c19328ff8f3f6a12784cf14c53e9e71 (patch) | |
tree | 863bdd4e90ea2d9be66c3164222611cff2aca04a /src/di_container/asynchronous/binding/builder.rs | |
parent | a34f7c03779aaf90f34b5ff59587daf1db42de8d (diff) |
refactor!: rename to_*default_factory functions to to_*dynamic_value
BREAKING CHANGE: The functions to_default_factory and
to_async_default_factory have been renamed to to_dynamic_value and
to_async_dynamic_value, respectively
Diffstat (limited to 'src/di_container/asynchronous/binding/builder.rs')
-rw-r--r-- | src/di_container/asynchronous/binding/builder.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs index 833517b..6f1281d 100644 --- a/src/di_container/asynchronous/binding/builder.rs +++ b/src/di_container/asynchronous/binding/builder.rs @@ -300,8 +300,8 @@ where Ok(AsyncBindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of type `Interface` to a factory that takes no arguments - /// inside of the associated [`AsyncDIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// function. /// /// # Errors /// Will return Err if the associated [`AsyncDIContainer`] already have a binding @@ -329,7 +329,7 @@ where /// # { /// # let mut di_container = AsyncDIContainer::new(); /// # - /// di_container.bind::<dyn Foo>().to_default_factory(&|_| { + /// di_container.bind::<dyn Foo>().to_dynamic_value(&|_| { /// Box::new(|| { /// let bar = TransientPtr::new(Bar { /// num: 42, @@ -345,16 +345,16 @@ where /// ``` #[cfg(feature = "factory")] #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_default_factory<Return, FactoryFunc>( + pub fn to_dynamic_value<Return, Func>( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result< AsyncBindingWhenConfigurator<'di_container, Interface>, AsyncBindingBuilderError, > where Return: 'static + ?Sized, - FactoryFunc: Fn(&AsyncDIContainer) -> BoxFn<(), crate::ptr::TransientPtr<Return>> + Func: Fn(&AsyncDIContainer) -> BoxFn<(), crate::ptr::TransientPtr<Return>> + Send + Sync, { @@ -373,12 +373,12 @@ where ))); } - let factory_impl = ThreadsafeCastableFunction::new(factory_func); + let castable_func = ThreadsafeCastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), Box::new(crate::provider::r#async::AsyncFunctionProvider::new( - Arc::new(factory_impl), + Arc::new(castable_func), ProvidableFunctionKind::Instant, )), ); @@ -386,8 +386,8 @@ where Ok(AsyncBindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of factory type `Interface` to a async factory inside of the - /// associated [`AsyncDIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// async function. /// /// # Errors /// Will return Err if the associated [`AsyncDIContainer`] already have a binding @@ -418,7 +418,7 @@ where /// # /// di_container /// .bind::<dyn Foo>() - /// .to_async_default_factory(&|_| { + /// .to_async_dynamic_value(&|_| { /// Box::new(|| { /// Box::pin(async { /// let bar = TransientPtr::new(Bar { @@ -438,16 +438,16 @@ where /// ``` #[cfg(feature = "factory")] #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_async_default_factory<Return, FactoryFunc>( + pub fn to_async_dynamic_value<Return, Func>( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result< AsyncBindingWhenConfigurator<'di_container, Interface>, AsyncBindingBuilderError, > where Return: 'static + ?Sized, - FactoryFunc: Fn(&AsyncDIContainer) -> BoxFn<(), crate::future::BoxFuture<'static, Return>> + Func: Fn(&AsyncDIContainer) -> BoxFn<(), crate::future::BoxFuture<'static, Return>> + Send + Sync, { @@ -466,12 +466,12 @@ where ))); } - let factory_impl = ThreadsafeCastableFunction::new(factory_func); + let castable_func = ThreadsafeCastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), Box::new(crate::provider::r#async::AsyncFunctionProvider::new( - Arc::new(factory_impl), + Arc::new(castable_func), ProvidableFunctionKind::AsyncInstant, )), ); @@ -608,7 +608,7 @@ mod tests #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_default_factory() + async fn can_bind_to_dynamic_value() { use crate::ptr::TransientPtr; @@ -633,7 +633,7 @@ mod tests ); binding_builder - .to_default_factory(&|_| { + .to_dynamic_value(&|_| { Box::new(|| { let user_manager: TransientPtr<dyn subjects_async::IUserManager> = TransientPtr::new(subjects_async::UserManager::new()); @@ -646,7 +646,7 @@ mod tests #[tokio::test] #[cfg(feature = "factory")] - async fn can_bind_to_async_default_factory() + async fn can_bind_to_async_dynamic_value() { use crate::ptr::TransientPtr; use crate::test_utils::async_closure; @@ -672,7 +672,7 @@ mod tests ); binding_builder - .to_async_default_factory(&|_| { + .to_async_dynamic_value(&|_| { async_closure!(|| { let user_manager: TransientPtr<dyn subjects_async::IUserManager> = TransientPtr::new(subjects_async::UserManager::new()); |