aboutsummaryrefslogtreecommitdiff
path: root/examples/async/animals
diff options
context:
space:
mode:
Diffstat (limited to 'examples/async/animals')
-rw-r--r--examples/async/animals/cat.rs22
-rw-r--r--examples/async/animals/dog.rs22
-rw-r--r--examples/async/animals/human.rs36
-rw-r--r--examples/async/animals/mod.rs3
4 files changed, 83 insertions, 0 deletions
diff --git a/examples/async/animals/cat.rs b/examples/async/animals/cat.rs
new file mode 100644
index 0000000..b1e6f27
--- /dev/null
+++ b/examples/async/animals/cat.rs
@@ -0,0 +1,22 @@
+use syrette::injectable;
+
+use crate::interfaces::cat::ICat;
+
+pub struct Cat {}
+
+#[injectable(ICat, { async = true })]
+impl Cat
+{
+ pub fn new() -> Self
+ {
+ Self {}
+ }
+}
+
+impl ICat for Cat
+{
+ fn meow(&self)
+ {
+ println!("Meow!");
+ }
+}
diff --git a/examples/async/animals/dog.rs b/examples/async/animals/dog.rs
new file mode 100644
index 0000000..d1b33f9
--- /dev/null
+++ b/examples/async/animals/dog.rs
@@ -0,0 +1,22 @@
+use syrette::injectable;
+
+use crate::interfaces::dog::IDog;
+
+pub struct Dog {}
+
+#[injectable(IDog, { async = true })]
+impl Dog
+{
+ pub fn new() -> Self
+ {
+ Self {}
+ }
+}
+
+impl IDog for Dog
+{
+ fn woof(&self)
+ {
+ println!("Woof!");
+ }
+}
diff --git a/examples/async/animals/human.rs b/examples/async/animals/human.rs
new file mode 100644
index 0000000..140f27c
--- /dev/null
+++ b/examples/async/animals/human.rs
@@ -0,0 +1,36 @@
+use syrette::injectable;
+use syrette::ptr::{ThreadsafeSingletonPtr, TransientPtr};
+
+use crate::interfaces::cat::ICat;
+use crate::interfaces::dog::IDog;
+use crate::interfaces::human::IHuman;
+
+pub struct Human
+{
+ dog: ThreadsafeSingletonPtr<dyn IDog>,
+ cat: TransientPtr<dyn ICat>,
+}
+
+#[injectable(IHuman, { async = true })]
+impl Human
+{
+ pub fn new(dog: ThreadsafeSingletonPtr<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/async/animals/mod.rs b/examples/async/animals/mod.rs
new file mode 100644
index 0000000..5444978
--- /dev/null
+++ b/examples/async/animals/mod.rs
@@ -0,0 +1,3 @@
+pub mod cat;
+pub mod dog;
+pub mod human;