From d46181de1c19328ff8f3f6a12784cf14c53e9e71 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 15 Sep 2024 23:33:33 +0200 Subject: 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 --- src/di_container/blocking/binding/builder.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/di_container/blocking') 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::().to_default_factory(&|_| { + /// di_container.bind::().to_dynamic_value(&|_| { /// Box::new(|| { /// let buffer = TransientPtr::new(Buffer::::new()); /// @@ -260,13 +260,13 @@ where /// ``` #[cfg(feature = "factory")] #[cfg_attr(doc_cfg, doc(cfg(feature = "factory")))] - pub fn to_default_factory( + pub fn to_dynamic_value( self, - factory_func: &'static FactoryFunc, + func: &'static Func, ) -> Result, BindingBuilderError> where Return: 'static + ?Sized, - FactoryFunc: Fn( + Func: Fn( &DIContainer, ) -> crate::ptr::TransientPtr< dyn Fn<(), Output = crate::ptr::TransientPtr>, @@ -286,12 +286,12 @@ where >())); } - let factory_impl = CastableFunction::new(factory_func); + let castable_func = CastableFunction::new(func); self.di_container.set_binding::( 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 = TransientPtr::new(subjects::UserManager::new()); -- cgit v1.2.3-18-g5258