From d4078c84a83d121a4e3492955359cedb3b404476 Mon Sep 17 00:00:00 2001
From: HampusM <hampus@hampusmat.com>
Date: Thu, 25 Aug 2022 20:46:14 +0200
Subject: refactor!: limit FactoryPtr & AnyFactory to the factory feature

BREAKING CHANGE: FactoryPtr has been limited to the factory feature
---
 src/di_container.rs        |  7 -------
 src/errors/di_container.rs |  4 ----
 src/interfaces/mod.rs      |  1 +
 src/provider.rs            | 13 +++++++------
 src/ptr.rs                 |  4 ++++
 5 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/di_container.rs b/src/di_container.rs
index 2cda2bf..85b0e7a 100644
--- a/src/di_container.rs
+++ b/src/di_container.rs
@@ -313,13 +313,6 @@ impl DIContainer
                     }
                 }
             }
-            #[cfg(not(feature = "factory"))]
-            Providable::Factory(_) => {
-                return Err(DIContainerError::CantHandleFactoryBinding(type_name::<
-                    Interface,
-                >(
-                )));
-            }
         }
     }
 
diff --git a/src/errors/di_container.rs b/src/errors/di_container.rs
index 4a74b5d..65cd9d1 100644
--- a/src/errors/di_container.rs
+++ b/src/errors/di_container.rs
@@ -29,10 +29,6 @@ pub enum DIContainerError
     /// No binding exists for a interface.
     #[error("No binding exists for interface '{0}'")]
     BindingNotFound(&'static str),
-
-    /// The binding for a interface is a factory but the factory feature isn't enabled.
-    #[error("The binding for interface '{0}' is a factory but the factory feature isn't enabled")]
-    CantHandleFactoryBinding(&'static str),
 }
 
 /// Error type for [`BindingBuilder`].
diff --git a/src/interfaces/mod.rs b/src/interfaces/mod.rs
index 0ea8ab5..73dde04 100644
--- a/src/interfaces/mod.rs
+++ b/src/interfaces/mod.rs
@@ -2,6 +2,7 @@
 
 pub mod injectable;
 
+#[cfg(feature = "factory")]
 #[doc(hidden)]
 pub mod any_factory;
 
diff --git a/src/provider.rs b/src/provider.rs
index ad94589..13674b9 100644
--- a/src/provider.rs
+++ b/src/provider.rs
@@ -2,9 +2,8 @@
 use std::marker::PhantomData;
 
 use crate::errors::injectable::InjectableError;
-use crate::interfaces::any_factory::AnyFactory;
 use crate::interfaces::injectable::Injectable;
-use crate::ptr::{FactoryPtr, SingletonPtr, TransientPtr};
+use crate::ptr::{SingletonPtr, TransientPtr};
 use crate::DIContainer;
 
 #[derive(strum_macros::Display, Debug)]
@@ -12,8 +11,8 @@ pub enum Providable
 {
     Transient(TransientPtr<dyn Injectable>),
     Singleton(SingletonPtr<dyn Injectable>),
-    #[allow(dead_code)]
-    Factory(FactoryPtr<dyn AnyFactory>),
+    #[cfg(feature = "factory")]
+    Factory(crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>),
 }
 
 pub trait IProvider
@@ -95,13 +94,15 @@ where
 #[cfg(feature = "factory")]
 pub struct FactoryProvider
 {
-    factory: FactoryPtr<dyn AnyFactory>,
+    factory: crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>,
 }
 
 #[cfg(feature = "factory")]
 impl FactoryProvider
 {
-    pub fn new(factory: FactoryPtr<dyn AnyFactory>) -> Self
+    pub fn new(
+        factory: crate::ptr::FactoryPtr<dyn crate::interfaces::any_factory::AnyFactory>,
+    ) -> Self
     {
         Self { factory }
     }
diff --git a/src/ptr.rs b/src/ptr.rs
index 08c3788..6f93fee 100644
--- a/src/ptr.rs
+++ b/src/ptr.rs
@@ -14,6 +14,7 @@ pub type TransientPtr<Interface> = Box<Interface>;
 pub type SingletonPtr<Interface> = Rc<Interface>;
 
 /// A smart pointer to a factory.
+#[cfg(feature = "factory")]
 pub type FactoryPtr<FactoryInterface> = Rc<FactoryInterface>;
 
 /// Some smart pointer.
@@ -29,6 +30,7 @@ where
     Singleton(SingletonPtr<Interface>),
 
     /// A smart pointer to a factory.
+    #[cfg(feature = "factory")]
     Factory(FactoryPtr<Interface>),
 }
 
@@ -63,5 +65,7 @@ where
 {
     create_as_variant_fn!(Transient);
     create_as_variant_fn!(Singleton);
+
+    #[cfg(feature = "factory")]
     create_as_variant_fn!(Factory);
 }
-- 
cgit v1.2.3-18-g5258