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/blocking/binding | |
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/blocking/binding')
-rw-r--r-- | src/di_container/blocking/binding/builder.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs index 345fb02..558db6e 100644 --- a/src/di_container/blocking/binding/builder.rs +++ b/src/di_container/blocking/binding/builder.rs @@ -208,8 +208,8 @@ where Ok(BindingWhenConfigurator::new(self.di_container)) } - /// Creates a binding of type `Interface` to a factory that takes no arguments - /// inside of the associated [`DIContainer`]. + /// Creates a binding of type `Interface` to a value resolved using the given + /// function. /// /// # Errors /// Will return Err if the associated [`DIContainer`] already have a binding for @@ -247,7 +247,7 @@ where /// # { /// # let mut di_container = DIContainer::new(); /// # - /// di_container.bind::<dyn IBuffer>().to_default_factory(&|_| { + /// di_container.bind::<dyn IBuffer>().to_dynamic_value(&|_| { /// Box::new(|| { /// let buffer = TransientPtr::new(Buffer::<BUFFER_SIZE>::new()); /// @@ -260,13 +260,13 @@ 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<BindingWhenConfigurator<'di_container, Interface>, BindingBuilderError> where Return: 'static + ?Sized, - FactoryFunc: Fn( + Func: Fn( &DIContainer, ) -> crate::ptr::TransientPtr< dyn Fn<(), Output = crate::ptr::TransientPtr<Return>>, @@ -286,12 +286,12 @@ where >())); } - let factory_impl = CastableFunction::new(factory_func); + let castable_func = CastableFunction::new(func); self.di_container.set_binding::<Interface>( BindingOptions::new(), Box::new(crate::provider::blocking::FunctionProvider::new( - Rc::new(factory_impl), + Rc::new(castable_func), ProvidableFunctionKind::Instant, )), ); @@ -377,7 +377,7 @@ mod tests #[test] #[cfg(feature = "factory")] - fn can_bind_to_default_factory() + fn can_bind_to_dynamic_value() { use crate::ptr::TransientPtr; @@ -401,7 +401,7 @@ mod tests ); binding_builder - .to_default_factory(&|_| { + .to_dynamic_value(&|_| { Box::new(move || { let user_manager: TransientPtr<dyn subjects::IUserManager> = TransientPtr::new(subjects::UserManager::new()); |