aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-09 20:52:34 +0200
committerHampusM <hampus@hampusmat.com>2022-07-09 20:52:34 +0200
commitb5149091a263b373cb1302d197a79ea94653d826 (patch)
treeee56fa0e21ca66fcc079758c47df73205a00dd0f
parent15d7309072658800339eaba0491ba87ba6e266b2 (diff)
refactor: move injectable type provider to own file
-rw-r--r--syrette/src/di_container.rs43
-rw-r--r--syrette/src/provider.rs46
2 files changed, 48 insertions, 41 deletions
diff --git a/syrette/src/di_container.rs b/syrette/src/di_container.rs
index ce0d829..7aa8225 100644
--- a/syrette/src/di_container.rs
+++ b/syrette/src/di_container.rs
@@ -7,48 +7,9 @@ use std::rc::Rc;
use error_stack::{Context, Report, ResultExt};
-use crate::injectable::{Injectable, ResolveError};
+use crate::injectable::Injectable;
use crate::libs::intertrait::cast_box::CastBox;
-
-trait IInjectableTypeProvider
-{
- fn provide(
- &self,
- di_container: &DIContainer,
- ) -> error_stack::Result<Box<dyn Injectable>, ResolveError>;
-}
-
-struct InjectableTypeProvider<InjectableType>
-where
- InjectableType: Injectable,
-{
- _phantom_data: PhantomData<InjectableType>,
-}
-
-impl<InjectableType> InjectableTypeProvider<InjectableType>
-where
- InjectableType: Injectable,
-{
- fn new() -> Self
- {
- Self {
- _phantom_data: PhantomData,
- }
- }
-}
-
-impl<InjectableType> IInjectableTypeProvider for InjectableTypeProvider<InjectableType>
-where
- InjectableType: Injectable,
-{
- fn provide(
- &self,
- di_container: &DIContainer,
- ) -> error_stack::Result<Box<dyn Injectable>, ResolveError>
- {
- Ok(InjectableType::resolve(di_container)?)
- }
-}
+use crate::provider::{IInjectableTypeProvider, InjectableTypeProvider};
pub struct BindingBuilder<'a, InterfaceTrait>
where
diff --git a/syrette/src/provider.rs b/syrette/src/provider.rs
new file mode 100644
index 0000000..090aaac
--- /dev/null
+++ b/syrette/src/provider.rs
@@ -0,0 +1,46 @@
+use std::marker::PhantomData;
+
+extern crate error_stack;
+
+use crate::injectable::{Injectable, ResolveError};
+use crate::DIContainer;
+
+pub trait IInjectableTypeProvider
+{
+ fn provide(
+ &self,
+ di_container: &DIContainer,
+ ) -> error_stack::Result<Box<dyn Injectable>, ResolveError>;
+}
+
+pub struct InjectableTypeProvider<InjectableType>
+where
+ InjectableType: Injectable,
+{
+ _phantom_data: PhantomData<InjectableType>,
+}
+
+impl<InjectableType> InjectableTypeProvider<InjectableType>
+where
+ InjectableType: Injectable,
+{
+ pub fn new() -> Self
+ {
+ Self {
+ _phantom_data: PhantomData,
+ }
+ }
+}
+
+impl<InjectableType> IInjectableTypeProvider for InjectableTypeProvider<InjectableType>
+where
+ InjectableType: Injectable,
+{
+ fn provide(
+ &self,
+ di_container: &DIContainer,
+ ) -> error_stack::Result<Box<dyn Injectable>, ResolveError>
+ {
+ Ok(InjectableType::resolve(di_container)?)
+ }
+}