aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/user_manager.rs
diff options
context:
space:
mode:
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()
+ );
+ }
+ }
+}