From 901878ee3f2bee6605b02d321cc4c92bc32fd5b0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 27 Jun 2026 08:44:57 +0900 Subject: refactor(composer): hold managers behind *Interface traits Composer/PartialComposer exposed its RepositoryManager, InstallationManager, EventDispatcher, Locker, DownloadManager, AutoloadGenerator and ArchiveManager as concrete types, but Composer's public setters (setDownloadManager() etc.) let plugins swap in subclasses. Introduce a *Interface trait per manager and store each as Rc> so a replacement is honored. Only Composer's slots and the sinks fed from its accessors become trait objects; managers injected concretely at construction keep their concrete references, matching PHP semantics. Fluent setters on the affected classes now return () and Locker::update_hash is de-generified to a boxed FnOnce so the traits stay object-safe. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/repository/repository_factory.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'crates/shirabe/src/repository/repository_factory.rs') diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs index db8185e..bc08589 100644 --- a/crates/shirabe/src/repository/repository_factory.rs +++ b/crates/shirabe/src/repository/repository_factory.rs @@ -15,6 +15,7 @@ use crate::json::JsonFile; use crate::repository::FilesystemRepository; use crate::repository::RepositoryInterfaceHandle; use crate::repository::RepositoryManager; +use crate::repository::RepositoryManagerInterface; use crate::util::HttpDownloader; use crate::util::ProcessExecutor; @@ -98,7 +99,7 @@ impl RepositoryFactory { config: &std::rc::Rc>, repository: &str, allow_filesystem: bool, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result { let repo_config = Self::config_from_string(io.clone(), config, repository, allow_filesystem)?; @@ -109,7 +110,7 @@ impl RepositoryFactory { io: std::rc::Rc>, config: &std::rc::Rc>, repo_config: IndexMap, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result { let mut owned_rm; let rm = if let Some(rm) = rm { @@ -134,7 +135,7 @@ impl RepositoryFactory { pub fn default_repos( io: Option>>, config: Option>>, - rm: Option<&mut RepositoryManager>, + rm: Option<&mut dyn RepositoryManagerInterface>, ) -> anyhow::Result> { let config = match config { Some(c) => c, @@ -235,7 +236,7 @@ impl RepositoryFactory { } fn create_repos( - rm: &mut RepositoryManager, + rm: &mut dyn RepositoryManagerInterface, repo_configs: Vec, ) -> anyhow::Result> { let mut repo_map: IndexMap = IndexMap::new(); -- cgit v1.3.1