aboutsummaryrefslogtreecommitdiff
path: root/examples/named/ninja.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-27 23:41:41 +0200
committerHampusM <hampus@hampusmat.com>2022-08-27 23:41:41 +0200
commite0f90a8e384615c79d7d51c66d19294d75e79391 (patch)
treef3df3d1cd92f7d4a978feaa5a9a5f773dd0901ee /examples/named/ninja.rs
parentd4078c84a83d121a4e3492955359cedb3b404476 (diff)
feat: implement named bindings
Diffstat (limited to 'examples/named/ninja.rs')
-rw-r--r--examples/named/ninja.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/named/ninja.rs b/examples/named/ninja.rs
new file mode 100644
index 0000000..2069f14
--- /dev/null
+++ b/examples/named/ninja.rs
@@ -0,0 +1,45 @@
+use syrette::injectable;
+use syrette::ptr::TransientPtr;
+
+use crate::interfaces::ninja::INinja;
+use crate::interfaces::weapon::IWeapon;
+
+pub struct Ninja
+{
+ strong_weapon: TransientPtr<dyn IWeapon>,
+ weak_weapon: TransientPtr<dyn IWeapon>,
+}
+
+#[injectable(INinja)]
+impl Ninja
+{
+ pub fn new(
+ #[rustfmt::skip] // Prevent rustfmt from turning this into a single line
+ #[syrette::named("strong")]
+ strong_weapon: TransientPtr<dyn IWeapon>,
+
+ #[rustfmt::skip] // Prevent rustfmt from turning this into a single line
+ #[named("weak")]
+ weak_weapon: TransientPtr<dyn IWeapon>,
+ ) -> Self
+ {
+ Self {
+ strong_weapon,
+ weak_weapon,
+ }
+ }
+}
+
+impl INinja for Ninja
+{
+ fn use_weapons(&self)
+ {
+ println!("Ninja is using his strong weapon!");
+
+ self.strong_weapon.use_it();
+
+ println!("Ninja is using his weak weapon!");
+
+ self.weak_weapon.use_it();
+ }
+}