From 080cc42bb1da09059dbc35049a7ded0649961e0c Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 29 Aug 2022 20:52:56 +0200 Subject: feat: implement async functionality --- src/di_container_binding_map.rs | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) (limited to 'src/di_container_binding_map.rs') diff --git a/src/di_container_binding_map.rs b/src/di_container_binding_map.rs index 4df889d..4aa246e 100644 --- a/src/di_container_binding_map.rs +++ b/src/di_container_binding_map.rs @@ -1,10 +1,7 @@ -use std::any::{type_name, TypeId}; +use std::any::TypeId; use ahash::AHashMap; -use crate::errors::di_container::DIContainerError; -use crate::provider::IProvider; - #[derive(Debug, PartialEq, Eq, Hash)] struct DIContainerBindingKey { @@ -12,12 +9,16 @@ struct DIContainerBindingKey name: Option<&'static str>, } -pub struct DIContainerBindingMap +pub struct DIContainerBindingMap +where + Provider: 'static + ?Sized, { - bindings: AHashMap>, + bindings: AHashMap>, } -impl DIContainerBindingMap +impl DIContainerBindingMap +where + Provider: 'static + ?Sized, { pub fn new() -> Self { @@ -26,33 +27,22 @@ impl DIContainerBindingMap } } - pub fn get( - &self, - name: Option<&'static str>, - ) -> Result<&dyn IProvider, DIContainerError> + pub fn get(&self, name: Option<&'static str>) -> Option<&Provider> where Interface: 'static + ?Sized, { let interface_typeid = TypeId::of::(); - Ok(self - .bindings + self.bindings .get(&DIContainerBindingKey { type_id: interface_typeid, name, }) - .ok_or_else(|| DIContainerError::BindingNotFound { - interface: type_name::(), - name, - })? - .as_ref()) + .map(|provider| provider.as_ref()) } - pub fn set( - &mut self, - name: Option<&'static str>, - provider: Box, - ) where + pub fn set(&mut self, name: Option<&'static str>, provider: Box) + where Interface: 'static + ?Sized, { let interface_typeid = TypeId::of::(); @@ -69,7 +59,7 @@ impl DIContainerBindingMap pub fn remove( &mut self, name: Option<&'static str>, - ) -> Option> + ) -> Option> where Interface: 'static + ?Sized, { -- cgit v1.2.3-18-g5258