diff options
author | HampusM <hampus@hampusmat.com> | 2022-08-20 15:14:13 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-08-21 18:17:50 +0200 |
commit | 47c68f7d70cfa8c639f72361d8d0362048647075 (patch) | |
tree | 871f3577e54f77aa51368f1e34012c1f4f31e44d /examples/factory/main.rs | |
parent | c4eccc81d9bfa472197a4f302df1c967081a0be5 (diff) |
docs: improve the factory example
Diffstat (limited to 'examples/factory/main.rs')
-rw-r--r-- | examples/factory/main.rs | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/examples/factory/main.rs b/examples/factory/main.rs index e2e80f1..bf3d43b 100644 --- a/examples/factory/main.rs +++ b/examples/factory/main.rs @@ -5,22 +5,11 @@ mod bootstrap; mod interfaces; mod user; +mod user_manager; use bootstrap::bootstrap; -use interfaces::user::IUser; -use interfaces::user::IUserFactory; -use syrette::ptr::FactoryPtr; -use syrette::ptr::TransientPtr; - -fn add_users( - users: &mut Vec<TransientPtr<dyn IUser>>, - user_factory: &FactoryPtr<IUserFactory>, -) -{ - users.push(user_factory("Bob", "1983-04-13", "abc1234")); - users.push(user_factory("Anna", "1998-01-20", "IlovemYCat")); - users.push(user_factory("David", "2000-11-05", "12345678")); -} + +use crate::interfaces::user_manager::IUserManager; fn main() { @@ -28,20 +17,11 @@ fn main() let di_container = bootstrap(); - let user_factory = di_container.get_factory::<IUserFactory>().unwrap(); - - let mut users = Vec::<TransientPtr<dyn IUser>>::new(); + let mut user_manager = di_container.get::<dyn IUserManager>().unwrap(); - add_users(&mut users, &user_factory); + user_manager.fill_with_users(); println!("Printing user information"); - for user in users { - println!( - "{}, born {}, password is '{}'", - user.get_name(), - user.get_date_of_birth(), - user.get_password() - ); - } + user_manager.print_users(); } |