//! An example involving an application use std::{cell::RefCell, collections::HashMap, fmt::Display, rc::Rc}; use dirk_framework::{ component, component::{builder::Builder, Component}, provides, }; fn main() { let user_name = "Bob".to_string(); let component = DirkApplicationComponent::builder() .cookies(MandatoryCookies {}) .user_name(user_name.clone()) .build(); let app = component.application(); app.run(); } #[component( cookies: scoped_instance_bind(C), user_name: cloned_instance_bind(U), application: static_bind(Application) [cookies, user_name] )] trait ApplicationComponent { fn application(&self) -> Application; } struct Application { cookies: Rc>, user_name: U, } #[provides] impl Application { fn new(cookies: Rc>, user_name: U) -> Self { Self { cookies, user_name } } } impl Application { fn run(&self) { println!( "Application running under user {} with cookies {:?}", self.user_name, self.cookies.borrow().get_cookies() ); } } trait Cookies { fn get_cookies(&self) -> HashMap; } struct MandatoryCookies {} impl Cookies for MandatoryCookies { fn get_cookies(&self) -> HashMap { let mut ret = HashMap::new(); ret.insert("sess".to_string(), "1234567890".to_string()); ret } }