From c7f53c5d7d581ebf76803650c63ec615b1558dc8 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Thu, 28 May 2026 03:31:41 +0900 Subject: refactor(composer): represent composer via trait-based handles Replace the PartialComposer/Composer structs and the single Rc> enum with PartialComposer and Composer traits (Composer: PartialComposer), InnerPartialComposer / InnerFullComposer data structs, and the handle types FullComposerHandle (impl Composer) and AnyComposerHandle (polymorphic enum, impl PartialComposer), plus their weak variants. Factory builds the full and partial graphs via separate Rc::new_cyclic branches that share a build_composer_base helper. Call sites now use trait methods that encapsulate borrowing instead of borrow_partial() / composer_full*(). Co-Authored-By: Claude Opus 4.7 --- crates/shirabe/src/installer/library_installer.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'crates/shirabe/src/installer/library_installer.rs') diff --git a/crates/shirabe/src/installer/library_installer.rs b/crates/shirabe/src/installer/library_installer.rs index c1fedef..b50dbff 100644 --- a/crates/shirabe/src/installer/library_installer.rs +++ b/crates/shirabe/src/installer/library_installer.rs @@ -9,7 +9,7 @@ use shirabe_php_shim::{ realpath, rmdir, rtrim, strpos, }; -use crate::composer::PartialComposerWeakHandle; +use crate::composer::{AnyComposerWeakHandle, Composer, PartialComposer}; use crate::downloader::DownloadManager; use crate::installer::BinaryInstaller; use crate::installer::BinaryPresenceInterface; @@ -24,7 +24,7 @@ use crate::util::Silencer; /// Package installation manager. #[derive(Debug)] pub struct LibraryInstaller { - pub(crate) composer: PartialComposerWeakHandle, + pub(crate) composer: AnyComposerWeakHandle, pub(crate) vendor_dir: String, pub(crate) download_manager: Option>>, pub(crate) io: std::rc::Rc>, @@ -37,7 +37,7 @@ impl LibraryInstaller { /// Initializes library installer. pub fn new( io: std::rc::Rc>, - composer: PartialComposerWeakHandle, + composer: AnyComposerWeakHandle, r#type: Option, filesystem: Option>>, binary_installer: Option, @@ -48,15 +48,13 @@ impl LibraryInstaller { let download_manager = composer_rc .as_full() - .map(|full| full.borrow().get_download_manager()); - - let composer_ref = composer_rc.borrow_partial(); + .map(|full| full.get_download_manager()); let filesystem = filesystem .unwrap_or_else(|| std::rc::Rc::new(std::cell::RefCell::new(Filesystem::new(None)))); let vendor_dir = rtrim( // TODO(phase-b): Config::get returns PhpMixed; coerce to String via get_str. - &composer_ref + &composer_rc .get_config() .borrow_mut() .get_str("vendor-dir") @@ -68,7 +66,7 @@ impl LibraryInstaller { // TODO(phase-b): pass io by reference/clone todo!("io reference"), rtrim( - &composer_ref + &composer_rc .get_config() .borrow_mut() .get_str("bin-dir") @@ -76,7 +74,7 @@ impl LibraryInstaller { Some("/"), ), // TODO(phase-b): Config::get returns PhpMixed; coerce to String via get_str. - composer_ref + composer_rc .get_config() .borrow_mut() .get_str("bin-compat") -- cgit v1.3.1