From 4cb3884e24b3cba3347ff93475bbabd6fe18d2fa Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 22 Jul 2022 13:25:45 +0200 Subject: refactor: make factories an optional feature --- examples/factory/main.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/factory/main.rs (limited to 'examples/factory/main.rs') 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>, + user_factory: &FactoryPtr, +) +{ + 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::().unwrap(); + + let mut users = Vec::>::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() + ); + } +} -- cgit v1.2.3-18-g5258