From d6f01bd571753dc2e9628418f94f66139438bcb3 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 30 Aug 2022 18:53:23 +0200 Subject: refactor: replace arc cast panic with an error --- src/async_di_container.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/async_di_container.rs') diff --git a/src/async_di_container.rs b/src/async_di_container.rs index 374746f..ecf3a41 100644 --- a/src/async_di_container.rs +++ b/src/async_di_container.rs @@ -66,6 +66,7 @@ use crate::errors::async_di_container::{ AsyncDIContainerError, }; use crate::interfaces::async_injectable::AsyncInjectable; +use crate::libs::intertrait::cast::error::CastError; use crate::libs::intertrait::cast::{CastArc, CastBox}; use crate::provider::r#async::{ AsyncProvidable, @@ -410,11 +411,26 @@ impl AsyncDIContainer )) } AsyncProvidable::Singleton(singleton_binding) => { - Ok(SomeThreadsafePtr::ThreadsafeSingleton( - singleton_binding.cast::().map_err(|_| { - AsyncDIContainerError::CastFailed(type_name::()) - })?, - )) + Ok( + SomeThreadsafePtr::ThreadsafeSingleton( + singleton_binding.cast::().map_err( + |err| match err { + CastError::NotArcCastable(_) => { + AsyncDIContainerError::InterfaceNotAsync(type_name::< + Interface, + >( + )) + } + CastError::CastFailed { from: _, to: _ } => { + AsyncDIContainerError::CastFailed(type_name::< + Interface, + >( + )) + } + }, + )?, + ), + ) } #[cfg(feature = "factory")] AsyncProvidable::Factory(factory_binding) => { -- cgit v1.2.3-18-g5258