aboutsummaryrefslogtreecommitdiff
path: root/examples/factory/main.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-07-22 13:25:45 +0200
committerHampusM <hampus@hampusmat.com>2022-07-22 13:25:45 +0200
commit4cb3884e24b3cba3347ff93475bbabd6fe18d2fa (patch)
tree2fa5e6d81de9dc39bd11d64797914e5d305d98e2 /examples/factory/main.rs
parent157f38bc2287dcb9a8b21ef3d5e33c569dc5136e (diff)
refactor: make factories an optional feature
Diffstat (limited to 'examples/factory/main.rs')
-rw-r--r--examples/factory/main.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/examples/factory/main.rs b/examples/factory/main.rs
new file mode 100644
index 0000000..c659f3e
--- /dev/null
+++ b/examples/factory/main.rs
@@ -0,0 +1,47 @@
+#![deny(clippy::all)]
+#![deny(clippy::pedantic)]
+#![allow(clippy::module_name_repetitions)]
+
+mod bootstrap;
+mod interfaces;
+mod user;
+
+use bootstrap::bootstrap;
+use interfaces::user::IUser;
+use interfaces::user::IUserFactory;
+use syrette::ptr::FactoryPtr;
+use syrette::ptr::InterfacePtr;
+
+fn add_users(
+ users: &mut Vec<InterfacePtr<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"));
+}
+
+fn main()
+{
+ println!("Hello, world!");
+
+ let di_container = bootstrap();
+
+ let user_factory = di_container.get_factory::<IUserFactory>().unwrap();
+
+ let mut users = Vec::<InterfacePtr<dyn IUser>>::new();
+
+ add_users(&mut users, &user_factory);
+
+ println!("Printing user information");
+
+ for user in users {
+ println!(
+ "{}, born {}, password is '{}'",
+ user.get_name(),
+ user.get_date_of_birth(),
+ user.get_password()
+ );
+ }
+}