From 607d8d50b76665b67ca6f3124aa81773bec110b7 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 25 Dec 2023 22:53:13 +0100 Subject: WIP Linkme dependency removal --- src/interfaces/async_injectable.rs | 30 ++++++++++++++++++++++++++++-- src/interfaces/injectable.rs | 30 ++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-) (limited to 'src/interfaces') diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs index 3600bac..cf903e7 100644 --- a/src/interfaces/async_injectable.rs +++ b/src/interfaces/async_injectable.rs @@ -1,17 +1,19 @@ //! Interface for structs that can be injected into or be injected to. use std::fmt::Debug; use std::future::ready; +use std::rc::Rc; +use std::sync::Arc; use crate::errors::injectable::InjectableError; use crate::future::BoxFuture; -use crate::private::cast::CastFromArc; use crate::ptr::TransientPtr; +use crate::ptr_buffer::PtrBuffer; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); /// Interface for structs that can be injected into or be injected to. -pub trait AsyncInjectable: CastFromArc +pub trait AsyncInjectable: 'static + Send + Sync { /// Resolves the dependencies of the injectable. /// @@ -24,6 +26,15 @@ pub trait AsyncInjectable: CastFromArc where Self: Sized + 'fut, 'di_container: 'fut; + + /// A. + fn into_ptr_buffer_box(self: Box) -> PtrBuffer; + + /// A. + fn into_ptr_buffer_rc(self: Rc) -> PtrBuffer; + + /// A. + fn into_ptr_buffer_arc(self: Arc) -> PtrBuffer; } impl Debug for dyn AsyncInjectable @@ -48,4 +59,19 @@ where { Box::pin(ready(Ok(TransientPtr::new(Self::default())))) } + + fn into_ptr_buffer_box(self: Box) -> PtrBuffer + { + PtrBuffer::new_from(self) + } + + fn into_ptr_buffer_rc(self: Rc) -> PtrBuffer + { + PtrBuffer::new_from(self) + } + + fn into_ptr_buffer_arc(self: Arc) -> PtrBuffer + { + PtrBuffer::new_from(self) + } } diff --git a/src/interfaces/injectable.rs b/src/interfaces/injectable.rs index 1d3a1a7..eb0839c 100644 --- a/src/interfaces/injectable.rs +++ b/src/interfaces/injectable.rs @@ -1,15 +1,17 @@ //! Interface for structs that can be injected into or be injected to. use std::fmt::Debug; +use std::rc::Rc; +use std::sync::Arc; use crate::errors::injectable::InjectableError; -use crate::private::cast::CastFrom; use crate::ptr::TransientPtr; +use crate::ptr_buffer::{PtrBuffer, SmartPtr}; use crate::util::use_double; use_double!(crate::dependency_history::DependencyHistory); /// Interface for structs that can be injected into or be injected to. -pub trait Injectable: CastFrom +pub trait Injectable: 'static { /// Resolves the dependencies of the injectable. /// @@ -21,6 +23,15 @@ pub trait Injectable: CastFrom ) -> Result, InjectableError> where Self: Sized; + + /// A. + fn into_ptr_buffer_box(self: Box) -> PtrBuffer; + + /// A. + fn into_ptr_buffer_rc(self: Rc) -> PtrBuffer; + + /// A. + fn into_ptr_buffer_arc(self: Arc) -> PtrBuffer; } impl Debug for dyn Injectable @@ -42,4 +53,19 @@ where { Ok(TransientPtr::new(Self::default())) } + + fn into_ptr_buffer_box(self: Box) -> PtrBuffer + { + PtrBuffer::new_from(SmartPtr::Box(self)) + } + + fn into_ptr_buffer_rc(self: Rc) -> PtrBuffer + { + PtrBuffer::new_from(SmartPtr::Rc(self)) + } + + fn into_ptr_buffer_arc(self: Arc) -> PtrBuffer + { + PtrBuffer::new_from(SmartPtr::Arc(self)) + } } -- cgit v1.2.3-18-g5258