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 --- README.md | 6 +++--- examples/basic/animals/human.rs | 8 ++++---- examples/factory/bootstrap.rs | 6 +++--- examples/factory/main.rs | 6 +++--- macros/src/injectable_impl.rs | 12 ++++++------ 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 +- 11 files changed, 41 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index f4f0e13..df3b50a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ The goal of Syrette is to be a simple, useful, convenient and familiar DI librar ## Example usage ```rust use syrette::{injectable, DIContainer}; -use syrette::ptr::InterfacePtr; +use syrette::ptr::TransientPtr; trait IWeapon { @@ -65,13 +65,13 @@ trait IWarrior } struct Warrior { - weapon: InterfacePtr, + weapon: TransientPtr, } #[injectable(IWarrior)] impl Warrior { - fn new(weapon: InterfacePtr) -> Self + fn new(weapon: TransientPtr) -> Self { Self { weapon } } diff --git a/examples/basic/animals/human.rs b/examples/basic/animals/human.rs index 00574a3..8e52b5b 100644 --- a/examples/basic/animals/human.rs +++ b/examples/basic/animals/human.rs @@ -1,5 +1,5 @@ use syrette::injectable; -use syrette::ptr::InterfacePtr; +use syrette::ptr::TransientPtr; use crate::interfaces::cat::ICat; use crate::interfaces::dog::IDog; @@ -7,14 +7,14 @@ use crate::interfaces::human::IHuman; pub struct Human { - dog: InterfacePtr, - cat: InterfacePtr, + dog: TransientPtr, + cat: TransientPtr, } #[injectable(IHuman)] impl Human { - pub fn new(dog: InterfacePtr, cat: InterfacePtr) -> Self + pub fn new(dog: TransientPtr, cat: TransientPtr) -> Self { Self { dog, cat } } diff --git a/examples/factory/bootstrap.rs b/examples/factory/bootstrap.rs index 5086b1a..1967c6a 100644 --- a/examples/factory/bootstrap.rs +++ b/examples/factory/bootstrap.rs @@ -1,4 +1,4 @@ -use syrette::ptr::InterfacePtr; +use syrette::ptr::TransientPtr; use syrette::DIContainer; // Interfaces @@ -14,8 +14,8 @@ pub fn bootstrap() -> DIContainer di_container .bind::() .to_factory(&|name, date_of_birth, password| { - let user: InterfacePtr = - InterfacePtr::new(User::new(name, date_of_birth, password)); + let user: TransientPtr = + TransientPtr::new(User::new(name, date_of_birth, password)); user }); diff --git a/examples/factory/main.rs b/examples/factory/main.rs index c659f3e..e2e80f1 100644 --- a/examples/factory/main.rs +++ b/examples/factory/main.rs @@ -10,10 +10,10 @@ use bootstrap::bootstrap; use interfaces::user::IUser; use interfaces::user::IUserFactory; use syrette::ptr::FactoryPtr; -use syrette::ptr::InterfacePtr; +use syrette::ptr::TransientPtr; fn add_users( - users: &mut Vec>, + users: &mut Vec>, user_factory: &FactoryPtr, ) { @@ -30,7 +30,7 @@ fn main() let user_factory = di_container.get_factory::().unwrap(); - let mut users = Vec::>::new(); + let mut users = Vec::>::new(); add_users(&mut users, &user_factory); diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs index 822a432..89346e8 100644 --- a/macros/src/injectable_impl.rs +++ b/macros/src/injectable_impl.rs @@ -60,12 +60,12 @@ impl InjectableImpl fn resolve( #di_container_var: &syrette::DIContainer ) -> syrette::libs::error_stack::Result< - syrette::ptr::InterfacePtr, + syrette::ptr::TransientPtr, syrette::errors::injectable::ResolveError> { use syrette::libs::error_stack::ResultExt; - return Ok(syrette::ptr::InterfacePtr::new(Self::new( + return Ok(syrette::ptr::TransientPtr::new(Self::new( #(#get_dependencies .change_context(syrette::errors::injectable::ResolveError) .attach_printable( @@ -191,9 +191,9 @@ impl InjectableImpl { let arg_type_path_string = Self::_path_to_string(&type_path.path); - arg_type_path_string == "InterfacePtr" - || arg_type_path_string == "ptr::InterfacePtr" - || arg_type_path_string == "syrrete::ptr::InterfacePtr" + arg_type_path_string == "TransientPtr" + || arg_type_path_string == "ptr::TransientPtr" + || arg_type_path_string == "syrrete::ptr::TransientPtr" || arg_type_path_string == "FactoryPtr" || arg_type_path_string == "ptr::FactoryPtr" || arg_type_path_string == "syrrete::ptr::FactoryPtr" @@ -233,7 +233,7 @@ impl InjectableImpl let opt_first_generic_arg = generic_args.first(); - // Assume a first generic argument exists because InterfacePtr and + // Assume a first generic argument exists because TransientPtr and // FactoryPtr requires one let first_generic_arg = opt_first_generic_arg.as_ref().unwrap(); 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