From 9ab2f550a25c3e4465afa025e4ffb1294b331bdb Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 19 Jul 2022 13:11:19 +0200 Subject: docs: split example into multiple files --- example/src/animals/human.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 example/src/animals/human.rs (limited to 'example/src/animals/human.rs') diff --git a/example/src/animals/human.rs b/example/src/animals/human.rs new file mode 100644 index 0000000..5bd2f8f --- /dev/null +++ b/example/src/animals/human.rs @@ -0,0 +1,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, + cat: InterfacePtr, + cow_factory: FactoryPtr, +} + +#[injectable(IHuman)] +impl Human +{ + pub fn new( + dog: InterfacePtr, + cat: InterfacePtr, + cow_factory: FactoryPtr, + ) -> 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 = (self.cow_factory)(3); + + cow.moo(); + } +} -- cgit v1.2.3-18-g5258