//! Submodules can be generic use shaku::{module, Component, HasComponent, Interface}; use std::sync::Arc; trait DbPool: Interface { fn get_connection(&self) -> &C; } #[derive(Debug, Default)] struct DbConnection; #[derive(Component)] #[shaku(interface = DbPool)] struct DbPoolImpl { #[shaku(default)] connection: C, } impl DbPool for DbPoolImpl { fn get_connection(&self) -> &C { &self.connection } } module! { MyModule { components = [DbPoolImpl], providers = [] } } module! { RootModule { components = [], providers = [], use MyModule { components = [DbPool], providers = [] } } } #[test] fn generic_submodules() { let my_module = Arc::new(MyModule::builder().build()); let root_module = RootModule::builder(my_module).build(); let db_pool: &dyn DbPool = root_module.resolve_ref(); let connection = db_pool.get_connection(); assert_eq!(format!("{:?}", connection), "DbConnection") }