From 3fbf26181f1b4b9e594debb103fd347bd93240ea Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 27 Jul 2022 15:17:33 +0200 Subject: refactor!: rename InterfacePtr to TransientPtr BREAKING CHANGE: InterfacePtr has been renamed to TransientPtr --- src/castable_factory.rs | 8 ++++---- src/di_container.rs | 22 +++++++++++----------- src/interfaces/factory.rs | 4 ++-- src/interfaces/injectable.rs | 4 ++-- src/provider.rs | 4 ++-- src/ptr.rs | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/castable_factory.rs b/src/castable_factory.rs index c50456c..5ff4db0 100644 --- a/src/castable_factory.rs +++ b/src/castable_factory.rs @@ -1,13 +1,13 @@ use crate::interfaces::any_factory::AnyFactory; use crate::interfaces::factory::IFactory; -use crate::ptr::InterfacePtr; +use crate::ptr::TransientPtr; pub struct CastableFactory where Args: 'static, ReturnInterface: 'static + ?Sized, { - func: &'static dyn Fn>, + func: &'static dyn Fn>, } impl CastableFactory @@ -16,7 +16,7 @@ where ReturnInterface: 'static + ?Sized, { pub fn new( - func: &'static dyn Fn>, + func: &'static dyn Fn>, ) -> Self { Self { func } @@ -58,7 +58,7 @@ where Args: 'static, ReturnInterface: 'static + ?Sized, { - type Output = InterfacePtr; + type Output = TransientPtr; extern "rust-call" fn call_once(self, args: Args) -> Self::Output { diff --git a/src/di_container.rs b/src/di_container.rs index 1f7700f..d1c757d 100644 --- a/src/di_container.rs +++ b/src/di_container.rs @@ -11,7 +11,7 @@ use crate::errors::di_container::DIContainerError; use crate::interfaces::injectable::Injectable; use crate::libs::intertrait::cast::CastBox; use crate::provider::{IProvider, InjectableTypeProvider, Providable}; -use crate::ptr::InterfacePtr; +use crate::ptr::TransientPtr; /// Binding builder for type `Interface` inside a [`DIContainer`]. pub struct BindingBuilder<'di_container_lt, Interface> @@ -53,7 +53,7 @@ where #[cfg(feature = "factory")] pub fn to_factory( &mut self, - factory_func: &'static dyn Fn>, + factory_func: &'static dyn Fn>, ) where Args: 'static, Return: 'static + ?Sized, @@ -151,7 +151,7 @@ impl DIContainer /// - The binding for `Interface` is not injectable pub fn get( &self, - ) -> error_stack::Result, DIContainerError> + ) -> error_stack::Result, DIContainerError> where Interface: 'static + ?Sized, { @@ -260,7 +260,7 @@ mod tests use super::*; use crate::errors::injectable::ResolveError; - use crate::ptr::InterfacePtr; + use crate::ptr::TransientPtr; #[test] fn can_bind_to() @@ -292,13 +292,13 @@ mod tests fn resolve( _di_container: &DIContainer, ) -> error_stack::Result< - InterfacePtr, + TransientPtr, crate::errors::injectable::ResolveError, > where Self: Sized, { - Ok(InterfacePtr::new(Self {})) + Ok(TransientPtr::new(Self {})) } } @@ -353,8 +353,8 @@ mod tests assert_eq!(di_container.bindings.len(), 0); di_container.bind::().to_factory(&|| { - let user_manager: InterfacePtr = - InterfacePtr::new(UserManager::new()); + let user_manager: TransientPtr = + TransientPtr::new(UserManager::new()); user_manager }); @@ -417,7 +417,7 @@ mod tests mock_provider.expect_provide().returning(|_| { Ok(Providable::Injectable( - InterfacePtr::new(UserManager::new()), + TransientPtr::new(UserManager::new()), )) }); @@ -495,8 +495,8 @@ mod tests mock_provider.expect_provide().returning(|_| { Ok(Providable::Factory(crate::ptr::FactoryPtr::new( CastableFactory::new(&|users| { - let user_manager: InterfacePtr = - InterfacePtr::new(UserManager::new(users)); + let user_manager: TransientPtr = + TransientPtr::new(UserManager::new(users)); user_manager }), diff --git a/src/interfaces/factory.rs b/src/interfaces/factory.rs index c97fc09..6f8e7c7 100644 --- a/src/interfaces/factory.rs +++ b/src/interfaces/factory.rs @@ -1,9 +1,9 @@ #![allow(clippy::module_name_repetitions)] use crate::libs::intertrait::CastFrom; -use crate::ptr::InterfacePtr; +use crate::ptr::TransientPtr; pub trait IFactory: - Fn> + CastFrom + Fn> + CastFrom where ReturnInterface: 'static + ?Sized, { diff --git a/src/interfaces/injectable.rs b/src/interfaces/injectable.rs index 24032a6..0af1217 100644 --- a/src/interfaces/injectable.rs +++ b/src/interfaces/injectable.rs @@ -1,6 +1,6 @@ use crate::errors::injectable::ResolveError; use crate::libs::intertrait::CastFrom; -use crate::ptr::InterfacePtr; +use crate::ptr::TransientPtr; use crate::DIContainer; pub trait Injectable: CastFrom @@ -11,7 +11,7 @@ pub trait Injectable: CastFrom /// Will return `Err` if resolving the dependencies fails. fn resolve( di_container: &DIContainer, - ) -> error_stack::Result, ResolveError> + ) -> error_stack::Result, ResolveError> where Self: Sized; } diff --git a/src/provider.rs b/src/provider.rs index bd17474..eb5b5d8 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -4,14 +4,14 @@ use std::marker::PhantomData; use crate::errors::injectable::ResolveError; use crate::interfaces::any_factory::AnyFactory; use crate::interfaces::injectable::Injectable; -use crate::ptr::{FactoryPtr, InterfacePtr}; +use crate::ptr::{FactoryPtr, TransientPtr}; use crate::DIContainer; extern crate error_stack; pub enum Providable { - Injectable(InterfacePtr), + Injectable(TransientPtr), #[allow(dead_code)] Factory(FactoryPtr), } diff --git a/src/ptr.rs b/src/ptr.rs index 414d086..62445fd 100644 --- a/src/ptr.rs +++ b/src/ptr.rs @@ -1,6 +1,6 @@ #![allow(clippy::module_name_repetitions)] use std::rc::Rc; -pub type InterfacePtr = Box; +pub type TransientPtr = Box; pub type FactoryPtr = Rc; -- cgit v1.2.3-18-g5258