aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-08-18 21:53:36 +0200
committerHampusM <hampus@hampusmat.com>2023-08-18 21:53:36 +0200
commitd9fb89865165bdd31807c3fbec2def6d3ebb7b53 (patch)
tree6bc1c5d92e6d2737c1525c933efbc19f632b0dde
parent055a98aec1fe534d78414d630ab5ba2b789cba64 (diff)
refactor: replace use_dependency_history with a more generic macro
-rw-r--r--src/di_container/asynchronous/binding/builder.rs4
-rw-r--r--src/di_container/asynchronous/binding/scope_configurator.rs4
-rw-r--r--src/di_container/asynchronous/mod.rs4
-rw-r--r--src/di_container/blocking/binding/builder.rs4
-rw-r--r--src/di_container/blocking/binding/scope_configurator.rs4
-rw-r--r--src/di_container/blocking/mod.rs4
-rw-r--r--src/interfaces/async_injectable.rs4
-rw-r--r--src/interfaces/injectable.rs4
-rw-r--r--src/provider/async.rs4
-rw-r--r--src/provider/blocking.rs4
-rw-r--r--src/test_utils.rs24
-rw-r--r--src/util.rs46
12 files changed, 68 insertions, 42 deletions
diff --git a/src/di_container/asynchronous/binding/builder.rs b/src/di_container/asynchronous/binding/builder.rs
index 9fa5115..5862d63 100644
--- a/src/di_container/asynchronous/binding/builder.rs
+++ b/src/di_container/asynchronous/binding/builder.rs
@@ -11,9 +11,9 @@ use crate::di_container::asynchronous::binding::when_configurator::AsyncBindingW
use crate::di_container::asynchronous::IAsyncDIContainer;
use crate::errors::async_di_container::AsyncBindingBuilderError;
use crate::interfaces::async_injectable::AsyncInjectable;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Alias for a threadsafe boxed function.
#[cfg(feature = "factory")]
diff --git a/src/di_container/asynchronous/binding/scope_configurator.rs b/src/di_container/asynchronous/binding/scope_configurator.rs
index a4a684b..0b5bad8 100644
--- a/src/di_container/asynchronous/binding/scope_configurator.rs
+++ b/src/di_container/asynchronous/binding/scope_configurator.rs
@@ -10,9 +10,9 @@ use crate::errors::async_di_container::AsyncBindingScopeConfiguratorError;
use crate::interfaces::async_injectable::AsyncInjectable;
use crate::provider::r#async::{AsyncSingletonProvider, AsyncTransientTypeProvider};
use crate::ptr::ThreadsafeSingletonPtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Scope configurator for a binding for type `Interface` inside a [`IAsyncDIContainer`].
///
diff --git a/src/di_container/asynchronous/mod.rs b/src/di_container/asynchronous/mod.rs
index 0db6782..2939ddd 100644
--- a/src/di_container/asynchronous/mod.rs
+++ b/src/di_container/asynchronous/mod.rs
@@ -66,9 +66,9 @@ use crate::private::cast::boxed::CastBox;
use crate::private::cast::error::CastError;
use crate::provider::r#async::{AsyncProvidable, IAsyncProvider};
use crate::ptr::SomePtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
pub mod binding;
pub mod prelude;
diff --git a/src/di_container/blocking/binding/builder.rs b/src/di_container/blocking/binding/builder.rs
index 91855f5..0c323ec 100644
--- a/src/di_container/blocking/binding/builder.rs
+++ b/src/di_container/blocking/binding/builder.rs
@@ -11,9 +11,9 @@ use crate::di_container::blocking::binding::when_configurator::BindingWhenConfig
use crate::di_container::blocking::IDIContainer;
use crate::errors::di_container::BindingBuilderError;
use crate::interfaces::injectable::Injectable;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Binding builder for type `Interface` inside a [`IDIContainer`].
///
diff --git a/src/di_container/blocking/binding/scope_configurator.rs b/src/di_container/blocking/binding/scope_configurator.rs
index 0e2437f..0aefa93 100644
--- a/src/di_container/blocking/binding/scope_configurator.rs
+++ b/src/di_container/blocking/binding/scope_configurator.rs
@@ -10,9 +10,9 @@ use crate::errors::di_container::BindingScopeConfiguratorError;
use crate::interfaces::injectable::Injectable;
use crate::provider::blocking::{SingletonProvider, TransientTypeProvider};
use crate::ptr::SingletonPtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Scope configurator for a binding for type `Interface` inside a [`IDIContainer`].
///
diff --git a/src/di_container/blocking/mod.rs b/src/di_container/blocking/mod.rs
index aa89aad..5a27f78 100644
--- a/src/di_container/blocking/mod.rs
+++ b/src/di_container/blocking/mod.rs
@@ -61,9 +61,9 @@ use crate::private::cast::boxed::CastBox;
use crate::private::cast::rc::CastRc;
use crate::provider::blocking::{IProvider, Providable};
use crate::ptr::SomePtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
pub mod binding;
pub mod prelude;
diff --git a/src/interfaces/async_injectable.rs b/src/interfaces/async_injectable.rs
index 2364ae1..56b263d 100644
--- a/src/interfaces/async_injectable.rs
+++ b/src/interfaces/async_injectable.rs
@@ -7,9 +7,9 @@ use crate::errors::injectable::InjectableError;
use crate::future::BoxFuture;
use crate::private::cast::CastFromArc;
use crate::ptr::TransientPtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Interface for structs that can be injected into or be injected to.
pub trait AsyncInjectable<DIContainerType>: CastFromArc
diff --git a/src/interfaces/injectable.rs b/src/interfaces/injectable.rs
index 82b773a..2622320 100644
--- a/src/interfaces/injectable.rs
+++ b/src/interfaces/injectable.rs
@@ -6,9 +6,9 @@ use crate::di_container::blocking::IDIContainer;
use crate::errors::injectable::InjectableError;
use crate::private::cast::CastFrom;
use crate::ptr::TransientPtr;
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
/// Interface for structs that can be injected into or be injected to.
pub trait Injectable<DIContainerType>: CastFrom
diff --git a/src/provider/async.rs b/src/provider/async.rs
index c2d0bfe..2a241a7 100644
--- a/src/provider/async.rs
+++ b/src/provider/async.rs
@@ -7,9 +7,9 @@ use crate::di_container::asynchronous::IAsyncDIContainer;
use crate::errors::injectable::InjectableError;
use crate::interfaces::async_injectable::AsyncInjectable;
use crate::ptr::{ThreadsafeSingletonPtr, TransientPtr};
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
#[derive(strum_macros::Display, Debug)]
pub enum AsyncProvidable<DIContainerType>
diff --git a/src/provider/blocking.rs b/src/provider/blocking.rs
index a18e997..373dabd 100644
--- a/src/provider/blocking.rs
+++ b/src/provider/blocking.rs
@@ -5,9 +5,9 @@ use crate::di_container::blocking::IDIContainer;
use crate::errors::injectable::InjectableError;
use crate::interfaces::injectable::Injectable;
use crate::ptr::{SingletonPtr, TransientPtr};
-use crate::util::use_dependency_history;
+use crate::util::use_double;
-use_dependency_history!();
+use_double!(crate::dependency_history::DependencyHistory);
#[derive(strum_macros::Display, Debug)]
pub enum Providable<DIContainerType>
diff --git a/src/test_utils.rs b/src/test_utils.rs
index 3d51ffe..1fe4417 100644
--- a/src/test_utils.rs
+++ b/src/test_utils.rs
@@ -12,7 +12,7 @@ pub mod subjects
use crate::private::cast::CastFromArc;
use crate::ptr::TransientPtr;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
pub trait IUserManager
{
@@ -45,7 +45,7 @@ pub mod subjects
}
use crate as syrette;
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
declare_interface!(UserManager -> IUserManager);
@@ -153,7 +153,7 @@ pub mod subjects_async
use crate::interfaces::async_injectable::AsyncInjectable;
use crate::ptr::TransientPtr;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
pub trait IUserManager: Send + Sync
{
@@ -186,7 +186,7 @@ pub mod subjects_async
}
use crate as syrette;
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
declare_interface!(UserManager -> IUserManager);
@@ -292,9 +292,9 @@ pub mod mocks
use crate::errors::di_container::DIContainerError;
use crate::provider::blocking::IProvider;
use crate::ptr::SomePtr;
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
mock! {
pub DIContainer {}
@@ -362,9 +362,9 @@ pub mod mocks
use crate::errors::async_di_container::AsyncDIContainerError;
use crate::provider::r#async::IAsyncProvider;
use crate::ptr::SomePtr;
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
mock! {
pub AsyncDIContainer {}
@@ -438,9 +438,9 @@ pub mod mocks
use crate::di_container::asynchronous::IAsyncDIContainer;
use crate::errors::injectable::InjectableError;
use crate::provider::r#async::{AsyncProvidable, IAsyncProvider};
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
mock! {
pub AsyncProvider<DIContainerType: IAsyncDIContainer> {}
@@ -472,9 +472,9 @@ pub mod mocks
use crate::di_container::blocking::IDIContainer;
use crate::errors::injectable::InjectableError;
use crate::provider::blocking::{IProvider, Providable};
- use crate::util::use_dependency_history;
+ use crate::util::use_double;
- use_dependency_history!();
+ use_double!(crate::dependency_history::DependencyHistory);
mock! {
pub Provider<DIContainerType>
diff --git a/src/util.rs b/src/util.rs
index 2d2d911..373d784 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,15 +1,41 @@
-#[cfg(not(test))]
-macro_rules! use_dependency_history {
- () => {
- use $crate::dependency_history::DependencyHistory;
+//! Internal utilities.
+
+/// Imports the specified item, prepending 'Mock' to the item identifier if the `test`
+/// configuration option is set.
+///
+/// # Examples
+/// ```ignore
+/// use_double!(crate::dependency_history::DependencyHistory);
+/// ```
+/// <br>
+///
+/// Expands to the following when `cfg(not(test))`
+/// ```ignore
+/// use crate::dependency_history::DependencyHistory;
+/// ```
+/// <br>
+///
+/// Expands to the following when `cfg(test)`
+/// ```ignore
+/// use crate::dependency_history::MockDependencyHistory as DependencyHistory;
+/// ```
+macro_rules! use_double {
+ ($([$($part: ident),*])? $item_path_part: ident :: $($next_part: tt)+) => {
+ use_double!(
+ [$($($part,)*)? $item_path_part]
+ $($next_part)+
+ );
};
-}
-#[cfg(test)]
-macro_rules! use_dependency_history {
- () => {
- use $crate::dependency_history::MockDependencyHistory as DependencyHistory;
+ ([$($part: ident),*] $item_path_part: ident) => {
+ #[cfg(not(test))]
+ use $($part::)* $item_path_part;
+
+ ::paste::paste! {
+ #[cfg(test)]
+ use $($part::)* [<Mock $item_path_part>] as $item_path_part;
+ }
};
}
-pub(crate) use use_dependency_history;
+pub(crate) use use_double;