aboutsummaryrefslogtreecommitdiff
path: root/src/di_container_binding_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/di_container_binding_map.rs')
-rw-r--r--src/di_container_binding_map.rs91
1 files changed, 0 insertions, 91 deletions
diff --git a/src/di_container_binding_map.rs b/src/di_container_binding_map.rs
deleted file mode 100644
index eb71ff7..0000000
--- a/src/di_container_binding_map.rs
+++ /dev/null
@@ -1,91 +0,0 @@
-use std::any::TypeId;
-
-use ahash::AHashMap;
-
-#[derive(Debug, PartialEq, Eq, Hash)]
-struct DIContainerBindingKey
-{
- type_id: TypeId,
- name: Option<&'static str>,
-}
-
-pub struct DIContainerBindingMap<Provider>
-where
- Provider: 'static + ?Sized,
-{
- bindings: AHashMap<DIContainerBindingKey, Box<Provider>>,
-}
-
-impl<Provider> DIContainerBindingMap<Provider>
-where
- Provider: 'static + ?Sized,
-{
- pub fn new() -> Self
- {
- Self {
- bindings: AHashMap::new(),
- }
- }
-
- #[allow(clippy::borrowed_box)]
- pub fn get<Interface>(&self, name: Option<&'static str>) -> Option<&Box<Provider>>
- where
- Interface: 'static + ?Sized,
- {
- let interface_typeid = TypeId::of::<Interface>();
-
- self.bindings.get(&DIContainerBindingKey {
- type_id: interface_typeid,
- name,
- })
- }
-
- pub fn set<Interface>(&mut self, name: Option<&'static str>, provider: Box<Provider>)
- where
- Interface: 'static + ?Sized,
- {
- let interface_typeid = TypeId::of::<Interface>();
-
- self.bindings.insert(
- DIContainerBindingKey {
- type_id: interface_typeid,
- name,
- },
- provider,
- );
- }
-
- pub fn remove<Interface>(
- &mut self,
- name: Option<&'static str>,
- ) -> Option<Box<Provider>>
- where
- Interface: 'static + ?Sized,
- {
- let interface_typeid = TypeId::of::<Interface>();
-
- self.bindings.remove(&DIContainerBindingKey {
- type_id: interface_typeid,
- name,
- })
- }
-
- pub fn has<Interface>(&self, name: Option<&'static str>) -> bool
- where
- Interface: 'static + ?Sized,
- {
- let interface_typeid = TypeId::of::<Interface>();
-
- self.bindings.contains_key(&DIContainerBindingKey {
- type_id: interface_typeid,
- name,
- })
- }
-
- /// Only used by tests in the `di_container` module.
- #[cfg(test)]
- pub fn count(&self) -> usize
- {
- self.bindings.len()
- }
-}