diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | examples/basic/animals/human.rs | 8 | ||||
-rw-r--r-- | examples/factory/bootstrap.rs | 6 | ||||
-rw-r--r-- | examples/factory/main.rs | 6 | ||||
-rw-r--r-- | macros/src/injectable_impl.rs | 12 | ||||
-rw-r--r-- | src/castable_factory.rs | 8 | ||||
-rw-r--r-- | src/di_container.rs | 22 | ||||
-rw-r--r-- | src/interfaces/factory.rs | 4 | ||||
-rw-r--r-- | src/interfaces/injectable.rs | 4 | ||||
-rw-r--r-- | src/provider.rs | 4 | ||||
-rw-r--r-- | src/ptr.rs | 2 |
11 files changed, 41 insertions, 41 deletions
@@ -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<dyn IWeapon>, + weapon: TransientPtr<dyn IWeapon>, } #[injectable(IWarrior)] impl Warrior { - fn new(weapon: InterfacePtr<dyn IWeapon>) -> Self + fn new(weapon: TransientPtr<dyn IWeapon>) -> 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<dyn IDog>, - cat: InterfacePtr<dyn ICat>, + dog: TransientPtr<dyn IDog>, + cat: TransientPtr<dyn ICat>, } #[injectable(IHuman)] impl Human { - pub fn new(dog: InterfacePtr<dyn IDog>, cat: InterfacePtr<dyn ICat>) -> Self + pub fn new(dog: TransientPtr<dyn IDog>, cat: TransientPtr<dyn ICat>) -> 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::<IUserFactory>() .to_factory(&|name, date_of_birth, password| { - let user: InterfacePtr<dyn IUser> = - InterfacePtr::new(User::new(name, date_of_birth, password)); + let user: TransientPtr<dyn IUser> = + 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<InterfacePtr<dyn IUser>>, + users: &mut Vec<TransientPtr<dyn IUser>>, user_factory: &FactoryPtr<IUserFactory>, ) { @@ -30,7 +30,7 @@ fn main() let user_factory = di_container.get_factory::<IUserFactory>().unwrap(); - let mut users = Vec::<InterfacePtr<dyn IUser>>::new(); + let mut users = Vec::<TransientPtr<dyn IUser>>::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<Self>, + syrette::ptr::TransientPtr<Self>, 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<Args, ReturnInterface> where Args: 'static, ReturnInterface: 'static + ?Sized, { - func: &'static dyn Fn<Args, Output = InterfacePtr<ReturnInterface>>, + func: &'static dyn Fn<Args, Output = TransientPtr<ReturnInterface>>, } impl<Args, ReturnInterface> CastableFactory<Args, ReturnInterface> @@ -16,7 +16,7 @@ where ReturnInterface: 'static + ?Sized, { pub fn new( - func: &'static dyn Fn<Args, Output = InterfacePtr<ReturnInterface>>, + func: &'static dyn Fn<Args, Output = TransientPtr<ReturnInterface>>, ) -> Self { Self { func } @@ -58,7 +58,7 @@ where Args: 'static, ReturnInterface: 'static + ?Sized, { - type Output = InterfacePtr<ReturnInterface>; + type Output = TransientPtr<ReturnInterface>; 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<Args, Return>( &mut self, - factory_func: &'static dyn Fn<Args, Output = InterfacePtr<Return>>, + factory_func: &'static dyn Fn<Args, Output = TransientPtr<Return>>, ) where Args: 'static, Return: 'static + ?Sized, @@ -151,7 +151,7 @@ impl DIContainer /// - The binding for `Interface` is not injectable pub fn get<Interface>( &self, - ) -> error_stack::Result<InterfacePtr<Interface>, DIContainerError> + ) -> error_stack::Result<TransientPtr<Interface>, 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<Self>, + TransientPtr<Self>, 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::<IUserManagerFactory>().to_factory(&|| { - let user_manager: InterfacePtr<dyn IUserManager> = - InterfacePtr::new(UserManager::new()); + let user_manager: TransientPtr<dyn IUserManager> = + 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<dyn IUserManager> = - InterfacePtr::new(UserManager::new(users)); + let user_manager: TransientPtr<dyn IUserManager> = + 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<Args, ReturnInterface>: - Fn<Args, Output = InterfacePtr<ReturnInterface>> + CastFrom + Fn<Args, Output = TransientPtr<ReturnInterface>> + 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<InterfacePtr<Self>, ResolveError> + ) -> error_stack::Result<TransientPtr<Self>, 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<dyn Injectable>), + Injectable(TransientPtr<dyn Injectable>), #[allow(dead_code)] Factory(FactoryPtr<dyn AnyFactory>), } @@ -1,6 +1,6 @@ #![allow(clippy::module_name_repetitions)] use std::rc::Rc; -pub type InterfacePtr<Interface> = Box<Interface>; +pub type TransientPtr<Interface> = Box<Interface>; pub type FactoryPtr<FactoryInterface> = Rc<FactoryInterface>; |