diff options
Diffstat (limited to 'examples/unbound/animals')
| -rw-r--r-- | examples/unbound/animals/cat.rs | 22 | ||||
| -rw-r--r-- | examples/unbound/animals/dog.rs | 22 | ||||
| -rw-r--r-- | examples/unbound/animals/human.rs | 35 | ||||
| -rw-r--r-- | examples/unbound/animals/mod.rs | 3 | 
4 files changed, 82 insertions, 0 deletions
| diff --git a/examples/unbound/animals/cat.rs b/examples/unbound/animals/cat.rs new file mode 100644 index 0000000..153ad4b --- /dev/null +++ b/examples/unbound/animals/cat.rs @@ -0,0 +1,22 @@ +use syrette::injectable; + +use crate::interfaces::cat::ICat; + +pub struct Cat {} + +#[injectable(ICat)] +impl Cat +{ +    pub fn new() -> Self +    { +        Self {} +    } +} + +impl ICat for Cat +{ +    fn meow(&self) +    { +        println!("Meow!"); +    } +} diff --git a/examples/unbound/animals/dog.rs b/examples/unbound/animals/dog.rs new file mode 100644 index 0000000..84959c0 --- /dev/null +++ b/examples/unbound/animals/dog.rs @@ -0,0 +1,22 @@ +use syrette::injectable; + +use crate::interfaces::dog::IDog; + +pub struct Dog {} + +#[injectable(IDog)] +impl Dog +{ +    pub fn new() -> Self +    { +        Self {} +    } +} + +impl IDog for Dog +{ +    fn woof(&self) +    { +        println!("Woof!"); +    } +} diff --git a/examples/unbound/animals/human.rs b/examples/unbound/animals/human.rs new file mode 100644 index 0000000..d9b848b --- /dev/null +++ b/examples/unbound/animals/human.rs @@ -0,0 +1,35 @@ +use syrette::injectable; +use syrette::ptr::{SingletonPtr, TransientPtr}; + +use crate::interfaces::cat::ICat; +use crate::interfaces::dog::IDog; +use crate::interfaces::human::IHuman; + +pub struct Human +{ +    dog: SingletonPtr<dyn IDog>, +    cat: TransientPtr<dyn ICat>, +} + +#[injectable(IHuman)] +impl Human +{ +    pub fn new(dog: SingletonPtr<dyn IDog>, cat: TransientPtr<dyn ICat>) -> Self +    { +        Self { dog, cat } +    } +} + +impl IHuman for Human +{ +    fn make_pets_make_sounds(&self) +    { +        println!("Hi doggy!"); + +        self.dog.woof(); + +        println!("Hi kitty!"); + +        self.cat.meow(); +    } +} diff --git a/examples/unbound/animals/mod.rs b/examples/unbound/animals/mod.rs new file mode 100644 index 0000000..5444978 --- /dev/null +++ b/examples/unbound/animals/mod.rs @@ -0,0 +1,3 @@ +pub mod cat; +pub mod dog; +pub mod human; | 
