aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-07-11 20:48:47 +0200
committerHampusM <hampus@hampusmat.com>2024-07-11 20:48:47 +0200
commitcde9d4b41a4b37612420ac522bc261147966efa5 (patch)
tree0a3e84e3e8ef622f3db5b7802c36ad29711ee5cc /src
parentebd6d71e7ef357c310264bf55001498928fb94c7 (diff)
refactor: move & rename AnyFactory and AnyThreadsafeFactory traits
Diffstat (limited to 'src')
-rw-r--r--src/any_factory.rs13
-rw-r--r--src/castable_factory/mod.rs9
-rw-r--r--src/castable_factory/threadsafe.rs9
-rw-r--r--src/lib.rs3
-rw-r--r--src/provider/async.rs26
-rw-r--r--src/provider/blocking.rs14
6 files changed, 38 insertions, 36 deletions
diff --git a/src/any_factory.rs b/src/any_factory.rs
deleted file mode 100644
index 3aee98f..0000000
--- a/src/any_factory.rs
+++ /dev/null
@@ -1,13 +0,0 @@
-//! Interface for any factory to ever exist.
-
-use std::any::Any;
-use std::fmt::Debug;
-
-/// Interface for any factory to ever exist.
-pub trait AnyFactory: Any + Debug
-{
- fn as_any(&self) -> &dyn Any;
-}
-
-/// Interface for any threadsafe factory to ever exist.
-pub trait AnyThreadsafeFactory: AnyFactory + Send + Sync + Debug {}
diff --git a/src/castable_factory/mod.rs b/src/castable_factory/mod.rs
index 196dc14..0cb2127 100644
--- a/src/castable_factory/mod.rs
+++ b/src/castable_factory/mod.rs
@@ -1,12 +1,17 @@
use std::any::{type_name, Any};
use std::fmt::Debug;
-use crate::any_factory::AnyFactory;
use crate::ptr::TransientPtr;
#[cfg(feature = "async")]
pub mod threadsafe;
+/// Interface for any castable factory.
+pub trait AnyCastableFactory: Any + Debug
+{
+ fn as_any(&self) -> &dyn Any;
+}
+
pub struct CastableFactory<ReturnInterface, DIContainerT>
where
ReturnInterface: 'static + ?Sized,
@@ -32,7 +37,7 @@ where
}
}
-impl<ReturnInterface, DIContainerT> AnyFactory
+impl<ReturnInterface, DIContainerT> AnyCastableFactory
for CastableFactory<ReturnInterface, DIContainerT>
where
ReturnInterface: 'static + ?Sized,
diff --git a/src/castable_factory/threadsafe.rs b/src/castable_factory/threadsafe.rs
index 5935d75..8b1e66d 100644
--- a/src/castable_factory/threadsafe.rs
+++ b/src/castable_factory/threadsafe.rs
@@ -1,9 +1,12 @@
use std::any::{type_name, Any};
use std::fmt::Debug;
-use crate::any_factory::{AnyFactory, AnyThreadsafeFactory};
+use crate::castable_factory::AnyCastableFactory;
use crate::ptr::TransientPtr;
+/// Interface for any threadsafe castable factory.
+pub trait AnyThreadsafeCastableFactory: AnyCastableFactory + Send + Sync + Debug {}
+
pub struct ThreadsafeCastableFactory<ReturnInterface, DIContainerT>
where
DIContainerT: 'static,
@@ -33,7 +36,7 @@ where
}
}
-impl<ReturnInterface, DIContainerT> AnyFactory
+impl<ReturnInterface, DIContainerT> AnyCastableFactory
for ThreadsafeCastableFactory<ReturnInterface, DIContainerT>
where
DIContainerT: 'static,
@@ -45,7 +48,7 @@ where
}
}
-impl<ReturnInterface, DIContainerT> AnyThreadsafeFactory
+impl<ReturnInterface, DIContainerT> AnyThreadsafeCastableFactory
for ThreadsafeCastableFactory<ReturnInterface, DIContainerT>
where
DIContainerT: 'static,
diff --git a/src/lib.rs b/src/lib.rs
index d93acc8..5544faa 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -113,9 +113,6 @@ mod util;
#[cfg(feature = "factory")]
mod castable_factory;
-#[cfg(feature = "factory")]
-mod any_factory;
-
#[cfg(test)]
#[cfg(not(tarpaulin_include))]
mod test_utils;
diff --git a/src/provider/async.rs b/src/provider/async.rs
index 3875363..6ccb082 100644
--- a/src/provider/async.rs
+++ b/src/provider/async.rs
@@ -16,15 +16,21 @@ pub enum AsyncProvidable<DIContainerT>
Singleton(ThreadsafeSingletonPtr<dyn AsyncInjectable<DIContainerT>>),
#[cfg(feature = "factory")]
Factory(
- crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>,
+ crate::ptr::ThreadsafeFactoryPtr<
+ dyn crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory,
+ >,
),
#[cfg(feature = "factory")]
DefaultFactory(
- crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>,
+ crate::ptr::ThreadsafeFactoryPtr<
+ dyn crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory,
+ >,
),
#[cfg(feature = "factory")]
AsyncDefaultFactory(
- crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>,
+ crate::ptr::ThreadsafeFactoryPtr<
+ dyn crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory,
+ >,
),
}
@@ -182,8 +188,9 @@ pub enum AsyncFactoryVariant
#[cfg(feature = "factory")]
pub struct AsyncFactoryProvider
{
- factory:
- crate::ptr::ThreadsafeFactoryPtr<dyn crate::any_factory::AnyThreadsafeFactory>,
+ factory: crate::ptr::ThreadsafeFactoryPtr<
+ dyn crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory,
+ >,
variant: AsyncFactoryVariant,
}
@@ -192,7 +199,7 @@ impl AsyncFactoryProvider
{
pub fn new(
factory: crate::ptr::ThreadsafeFactoryPtr<
- dyn crate::any_factory::AnyThreadsafeFactory,
+ dyn crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory,
>,
variant: AsyncFactoryVariant,
) -> Self
@@ -302,13 +309,14 @@ mod tests
{
use std::any::Any;
- use crate::any_factory::{AnyFactory, AnyThreadsafeFactory};
+ use crate::castable_factory::threadsafe::AnyThreadsafeCastableFactory;
+ use crate::castable_factory::AnyCastableFactory;
use crate::ptr::ThreadsafeFactoryPtr;
#[derive(Debug)]
struct FooFactory;
- impl AnyFactory for FooFactory
+ impl AnyCastableFactory for FooFactory
{
fn as_any(&self) -> &dyn Any
{
@@ -316,7 +324,7 @@ mod tests
}
}
- impl AnyThreadsafeFactory for FooFactory {}
+ impl AnyThreadsafeCastableFactory for FooFactory {}
let factory_provider = AsyncFactoryProvider::new(
ThreadsafeFactoryPtr::new(FooFactory),
diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs
index bde3be5..65e315d 100644
--- a/src/provider/blocking.rs
+++ b/src/provider/blocking.rs
@@ -13,9 +13,11 @@ pub enum Providable<DIContainerType>
Transient(TransientPtr<dyn Injectable<DIContainerType>>),
Singleton(SingletonPtr<dyn Injectable<DIContainerType>>),
#[cfg(feature = "factory")]
- Factory(crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>),
+ Factory(crate::ptr::FactoryPtr<dyn crate::castable_factory::AnyCastableFactory>),
#[cfg(feature = "factory")]
- DefaultFactory(crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>),
+ DefaultFactory(
+ crate::ptr::FactoryPtr<dyn crate::castable_factory::AnyCastableFactory>,
+ ),
}
#[cfg_attr(test, mockall::automock)]
@@ -108,7 +110,7 @@ where
#[cfg(feature = "factory")]
pub struct FactoryProvider
{
- factory: crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>,
+ factory: crate::ptr::FactoryPtr<dyn crate::castable_factory::AnyCastableFactory>,
is_default_factory: bool,
}
@@ -116,7 +118,7 @@ pub struct FactoryProvider
impl FactoryProvider
{
pub fn new(
- factory: crate::ptr::FactoryPtr<dyn crate::any_factory::AnyFactory>,
+ factory: crate::ptr::FactoryPtr<dyn crate::castable_factory::AnyCastableFactory>,
is_default_factory: bool,
) -> Self
{
@@ -198,13 +200,13 @@ mod tests
{
use std::any::Any;
- use crate::any_factory::AnyFactory;
+ use crate::castable_factory::AnyCastableFactory;
use crate::ptr::FactoryPtr;
#[derive(Debug)]
struct FooFactory;
- impl AnyFactory for FooFactory
+ impl AnyCastableFactory for FooFactory
{
fn as_any(&self) -> &dyn Any
{