aboutsummaryrefslogtreecommitdiff
path: root/src/async_di_container.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-30 18:53:23 +0200
committerHampusM <hampus@hampusmat.com>2022-08-30 18:53:23 +0200
commitd6f01bd571753dc2e9628418f94f66139438bcb3 (patch)
tree1ed5492d8abdeb9231d498e9ecf349c7cc1ec3d8 /src/async_di_container.rs
parent080cc42bb1da09059dbc35049a7ded0649961e0c (diff)
refactor: replace arc cast panic with an error
Diffstat (limited to 'src/async_di_container.rs')
-rw-r--r--src/async_di_container.rs26
1 files changed, 21 insertions, 5 deletions
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::<Interface>().map_err(|_| {
- AsyncDIContainerError::CastFailed(type_name::<Interface>())
- })?,
- ))
+ Ok(
+ SomeThreadsafePtr::ThreadsafeSingleton(
+ singleton_binding.cast::<Interface>().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) => {