From 4cb3884e24b3cba3347ff93475bbabd6fe18d2fa Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 22 Jul 2022 13:25:45 +0200 Subject: refactor: make factories an optional feature --- examples/basic/animals/cow.rs | 24 ------------------------ examples/basic/animals/human.rs | 20 +++----------------- examples/basic/animals/mod.rs | 1 - examples/basic/bootstrap.rs | 7 ------- examples/basic/interfaces/cow.rs | 10 ---------- examples/basic/interfaces/mod.rs | 1 - 6 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 examples/basic/animals/cow.rs delete mode 100644 examples/basic/interfaces/cow.rs (limited to 'examples/basic') diff --git a/examples/basic/animals/cow.rs b/examples/basic/animals/cow.rs deleted file mode 100644 index a75d750..0000000 --- a/examples/basic/animals/cow.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::interfaces::cow::ICow; - -pub struct Cow -{ - moo_cnt: i32, -} - -impl Cow -{ - pub fn new(moo_cnt: i32) -> Self - { - Self { moo_cnt } - } -} - -impl ICow for Cow -{ - fn moo(&self) - { - for _ in 0..self.moo_cnt { - println!("Moo"); - } - } -} diff --git a/examples/basic/animals/human.rs b/examples/basic/animals/human.rs index 5bd2f8f..00574a3 100644 --- a/examples/basic/animals/human.rs +++ b/examples/basic/animals/human.rs @@ -1,8 +1,7 @@ use syrette::injectable; -use syrette::ptr::{FactoryPtr, InterfacePtr}; +use syrette::ptr::InterfacePtr; use crate::interfaces::cat::ICat; -use crate::interfaces::cow::{CowFactory, ICow}; use crate::interfaces::dog::IDog; use crate::interfaces::human::IHuman; @@ -10,23 +9,14 @@ pub struct Human { dog: InterfacePtr, cat: InterfacePtr, - cow_factory: FactoryPtr, } #[injectable(IHuman)] impl Human { - pub fn new( - dog: InterfacePtr, - cat: InterfacePtr, - cow_factory: FactoryPtr, - ) -> Self + pub fn new(dog: InterfacePtr, cat: InterfacePtr) -> Self { - Self { - dog, - cat, - cow_factory, - } + Self { dog, cat } } } @@ -41,9 +31,5 @@ impl IHuman for Human println!("Hi kitty!"); self.cat.meow(); - - let cow: Box = (self.cow_factory)(3); - - cow.moo(); } } diff --git a/examples/basic/animals/mod.rs b/examples/basic/animals/mod.rs index 6511d17..5444978 100644 --- a/examples/basic/animals/mod.rs +++ b/examples/basic/animals/mod.rs @@ -1,4 +1,3 @@ pub mod cat; -pub mod cow; pub mod dog; pub mod human; diff --git a/examples/basic/bootstrap.rs b/examples/basic/bootstrap.rs index a1a7b05..71ef713 100644 --- a/examples/basic/bootstrap.rs +++ b/examples/basic/bootstrap.rs @@ -2,13 +2,11 @@ use syrette::DIContainer; // Concrete implementations use crate::animals::cat::Cat; -use crate::animals::cow::Cow; use crate::animals::dog::Dog; use crate::animals::human::Human; // // Interfaces use crate::interfaces::cat::ICat; -use crate::interfaces::cow::{CowFactory, ICow}; use crate::interfaces::dog::IDog; use crate::interfaces::human::IHuman; @@ -20,10 +18,5 @@ pub fn bootstrap() -> DIContainer di_container.bind::().to::(); di_container.bind::().to::(); - di_container.bind::().to_factory(&|moo_cnt| { - let cow: Box = Box::new(Cow::new(moo_cnt)); - cow - }); - di_container } diff --git a/examples/basic/interfaces/cow.rs b/examples/basic/interfaces/cow.rs deleted file mode 100644 index 59ce7b1..0000000 --- a/examples/basic/interfaces/cow.rs +++ /dev/null @@ -1,10 +0,0 @@ -use syrette::factory; -use syrette::interfaces::factory::IFactory; - -pub trait ICow -{ - fn moo(&self); -} - -#[factory] -pub type CowFactory = dyn IFactory<(i32,), dyn ICow>; diff --git a/examples/basic/interfaces/mod.rs b/examples/basic/interfaces/mod.rs index 6511d17..5444978 100644 --- a/examples/basic/interfaces/mod.rs +++ b/examples/basic/interfaces/mod.rs @@ -1,4 +1,3 @@ pub mod cat; -pub mod cow; pub mod dog; pub mod human; -- cgit v1.2.3-18-g5258