diff options
author | HampusM <hampus@hampusmat.com> | 2022-07-22 13:25:45 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-07-22 13:25:45 +0200 |
commit | 4cb3884e24b3cba3347ff93475bbabd6fe18d2fa (patch) | |
tree | 2fa5e6d81de9dc39bd11d64797914e5d305d98e2 /examples/basic/animals | |
parent | 157f38bc2287dcb9a8b21ef3d5e33c569dc5136e (diff) |
refactor: make factories an optional feature
Diffstat (limited to 'examples/basic/animals')
-rw-r--r-- | examples/basic/animals/cow.rs | 24 | ||||
-rw-r--r-- | examples/basic/animals/human.rs | 20 | ||||
-rw-r--r-- | examples/basic/animals/mod.rs | 1 |
3 files changed, 3 insertions, 42 deletions
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<dyn IDog>, cat: InterfacePtr<dyn ICat>, - cow_factory: FactoryPtr<CowFactory>, } #[injectable(IHuman)] impl Human { - pub fn new( - dog: InterfacePtr<dyn IDog>, - cat: InterfacePtr<dyn ICat>, - cow_factory: FactoryPtr<CowFactory>, - ) -> Self + pub fn new(dog: InterfacePtr<dyn IDog>, cat: InterfacePtr<dyn ICat>) -> 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<dyn ICow> = (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; |