diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-20 18:06:42 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-21 18:17:51 +0200 |
commit | 55f5e8ca096467be2db895b459760ec34b63fce6 (patch) | |
tree | bb34d7f74d5ee7e423e57dbdfd9865d0115b0ff9 /examples/unbound/animals/human.rs | |
parent | 12acab96a7d9ba8032378f8be7b6932f4406a849 (diff) |
docs: add example for displaying a unbound interface error
Diffstat (limited to 'examples/unbound/animals/human.rs')
-rw-r--r-- | examples/unbound/animals/human.rs | 35 |
1 files changed, 35 insertions, 0 deletions
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(); + } +} |