diff options
author | HampusM <hampus@hampusmat.com> | 2023-12-25 22:53:13 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-12-28 12:00:11 +0100 |
commit | 607d8d50b76665b67ca6f3124aa81773bec110b7 (patch) | |
tree | 142a7c17c4e254eabd5a5396975921bca1869bec /src/di_container | |
parent | c501a5cc770f632eba1529de09bd3ae2d7958de6 (diff) |
WIP Linkme dependency removalwithout-linkme
Diffstat (limited to 'src/di_container')
-rw-r--r-- | src/di_container/asynchronous/mod.rs | 50 | ||||
-rw-r--r-- | src/di_container/blocking/mod.rs | 32 |
2 files changed, 36 insertions, 46 deletions
diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs index 3e29ef6..e5fd1fd 100644 --- a/src/di_container/asynchronous/mod.rs +++ b/src/di_container/asynchronous/mod.rs @@ -55,9 +55,6 @@ use crate::di_container::asynchronous::binding::builder::AsyncBindingBuilder; use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::BindingOptions; use crate::errors::async_di_container::AsyncDIContainerError; -use crate::private::cast::arc::CastArc; -use crate::private::cast::boxed::CastBox; -use crate::private::cast::error::CastError; use crate::provider::r#async::{AsyncProvidable, IAsyncProvider}; use crate::ptr::SomePtr; use crate::util::use_double; @@ -313,38 +310,27 @@ impl AsyncDIContainer Interface: 'static + ?Sized + Send + Sync, { match binding_providable { - AsyncProvidable::Transient(transient_binding) => Ok(SomePtr::Transient( - transient_binding.cast::<Interface>().map_err(|_| { - AsyncDIContainerError::CastFailed { + AsyncProvidable::Transient(transient_binding) => { + let ptr_buf = transient_binding.into_ptr_buffer_box(); + + ptr_buf + .cast_into_boxed::<Interface>() + .ok_or_else(|| AsyncDIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "transient", - } - })?, - )), + }) + .map(SomePtr::Transient) + } AsyncProvidable::Singleton(singleton_binding) => { - Ok(SomePtr::ThreadsafeSingleton( - singleton_binding - .cast::<Interface>() - .map_err(|err| match err { - CastError::NotArcCastable(_) => { - AsyncDIContainerError::InterfaceNotAsync(type_name::< - Interface, - >( - )) - } - CastError::CastFailed { - source: _, - from: _, - to: _, - } - | CastError::GetCasterFailed(_) => { - AsyncDIContainerError::CastFailed { - interface: type_name::<Interface>(), - binding_kind: "singleton", - } - } - })?, - )) + let ptr_buf = singleton_binding.into_ptr_buffer_arc(); + + ptr_buf + .cast_into_arc::<Interface>() + .ok_or_else(|| AsyncDIContainerError::CastFailed { + interface: type_name::<Interface>(), + binding_kind: "singleton", + }) + .map(SomePtr::ThreadsafeSingleton) } #[cfg(feature = "factory")] AsyncProvidable::Factory(factory_binding) => { diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs index d9efe94..7286f48 100644 --- a/src/di_container/blocking/mod.rs +++ b/src/di_container/blocking/mod.rs @@ -55,8 +55,6 @@ use crate::di_container::binding_storage::DIContainerBindingStorage; use crate::di_container::blocking::binding::builder::BindingBuilder; use crate::di_container::BindingOptions; use crate::errors::di_container::DIContainerError; -use crate::private::cast::boxed::CastBox; -use crate::private::cast::rc::CastRc; use crate::provider::blocking::{IProvider, Providable}; use crate::ptr::SomePtr; use crate::util::use_double; @@ -267,22 +265,28 @@ impl DIContainer .get_binding_providable::<Interface>(binding_options, dependency_history)?; match binding_providable { - Providable::Transient(transient_binding) => Ok(SomePtr::Transient( - transient_binding.cast::<Interface>().map_err(|_| { - DIContainerError::CastFailed { + Providable::Transient(transient_binding) => { + let ptr_buf = transient_binding.into_ptr_buffer_box(); + + ptr_buf + .cast_into_boxed::<Interface>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "transient", - } - })?, - )), - Providable::Singleton(singleton_binding) => Ok(SomePtr::Singleton( - singleton_binding.cast::<Interface>().map_err(|_| { - DIContainerError::CastFailed { + }) + .map(SomePtr::Transient) + } + Providable::Singleton(singleton_binding) => { + let ptr_buf = singleton_binding.into_ptr_buffer_rc(); + + ptr_buf + .cast_into_rc::<Interface>() + .ok_or_else(|| DIContainerError::CastFailed { interface: type_name::<Interface>(), binding_kind: "singleton", - } - })?, - )), + }) + .map(SomePtr::Singleton) + } #[cfg(feature = "factory")] Providable::Factory(factory_binding) => { use crate::castable_factory::CastableFactory; |