aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/user_manager.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-20 15:14:13 +0200
committerHampusM <hampus@hampusmat.com>2022-08-21 18:17:50 +0200
commit47c68f7d70cfa8c639f72361d8d0362048647075 (patch)
tree871f3577e54f77aa51368f1e34012c1f4f31e44d /examples/factory/user_manager.rs
parentc4eccc81d9bfa472197a4f302df1c967081a0be5 (diff)
docs: improve the factory example
Diffstat (limited to 'examples/factory/user_manager.rs')
-rw-r--r--examples/factory/user_manager.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/examples/factory/user_manager.rs b/examples/factory/user_manager.rs
new file mode 100644
index 0000000..32ccbe9
--- /dev/null
+++ b/examples/factory/user_manager.rs
@@ -0,0 +1,50 @@
+use syrette::injectable;
+use syrette::ptr::{FactoryPtr, TransientPtr};
+
+use crate::interfaces::user::{IUser, IUserFactory};
+use crate::interfaces::user_manager::IUserManager;
+
+pub struct UserManager
+{
+ users: Vec<TransientPtr<dyn IUser>>,
+ user_factory: FactoryPtr<IUserFactory>,
+}
+
+#[injectable(IUserManager)]
+impl UserManager
+{
+ pub fn new(user_factory: FactoryPtr<IUserFactory>) -> Self
+ {
+ Self {
+ users: Vec::new(),
+ user_factory,
+ }
+ }
+}
+
+impl IUserManager for UserManager
+{
+ fn fill_with_users(&mut self)
+ {
+ self.users
+ .push((self.user_factory)("Bob", "1983-04-13", "abc1234"));
+
+ self.users
+ .push((self.user_factory)("Anna", "1998-01-20", "IlovemYCat"));
+
+ self.users
+ .push((self.user_factory)("David", "2000-11-05", "12345678"));
+ }
+
+ fn print_users(&self)
+ {
+ for user in &self.users {
+ println!(
+ "{}, born {}, password is '{}'",
+ user.get_name(),
+ user.get_date_of_birth(),
+ user.get_password()
+ );
+ }
+ }
+}