aboutsummaryrefslogtreecommitdiff
path: root/examples/basic/animals/human.rs
blob: 5bd2f8f56bcfe61d241e97a53e2ee574c3d805cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use syrette::injectable;
use syrette::ptr::{FactoryPtr, InterfacePtr};

use crate::interfaces::cat::ICat;
use crate::interfaces::cow::{CowFactory, ICow};
use crate::interfaces::dog::IDog;
use crate::interfaces::human::IHuman;

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
    {
        Self {
            dog,
            cat,
            cow_factory,
        }
    }
}

impl IHuman for Human
{
    fn make_pets_make_sounds(&self)
    {
        println!("Hi doggy!");

        self.dog.woof();

        println!("Hi kitty!");

        self.cat.meow();

        let cow: Box<dyn ICow> = (self.cow_factory)(3);

        cow.moo();
    }
}