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/command/base_command.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'crates/shirabe/src/command/base_command.rs') diff --git a/crates/shirabe/src/command/base_command.rs b/crates/shirabe/src/command/base_command.rs index 6b673ed..cf121dc 100644 --- a/crates/shirabe/src/command/base_command.rs +++ b/crates/shirabe/src/command/base_command.rs @@ -19,7 +19,7 @@ use std::rc::Rc; use crate::advisory::AuditConfig; use crate::advisory::Auditor; use crate::command::SelfUpdateCommand; -use crate::composer::PartialComposerHandle; +use crate::composer::{AnyComposerHandle, PartialComposer}; use crate::config::Config; use crate::console::Application; use crate::console::input::InputArgument; @@ -163,23 +163,23 @@ pub trait BaseCommand { required: bool, disable_plugins: Option, disable_scripts: Option, - ) -> Result>; + ) -> Result>; /// Retrieves the default Composer\Composer instance or throws fn require_composer( &mut self, disable_plugins: Option, disable_scripts: Option, - ) -> Result; + ) -> Result; /// Retrieves the default Composer\Composer instance or null fn try_composer( &mut self, disable_plugins: Option, disable_scripts: Option, - ) -> Option; + ) -> Option; - fn set_composer(&mut self, composer: PartialComposerHandle); + fn set_composer(&mut self, composer: AnyComposerHandle); /// Removes the cached composer instance fn reset_composer(&mut self) -> Result<()>; @@ -208,7 +208,7 @@ pub trait BaseCommand { config: Option>, disable_plugins: bool, disable_scripts: Option, - ) -> Result; + ) -> Result; /// Returns preferSource and preferDist values based on the configuration. fn get_preferred_install_options( @@ -256,7 +256,7 @@ pub trait BaseCommand { #[derive(Debug)] pub struct BaseCommandData { - pub(crate) composer: Option, + pub(crate) composer: Option, pub(crate) io: Option>>, } @@ -264,11 +264,11 @@ pub trait HasBaseCommandData { fn base_command_data(&self) -> &BaseCommandData; fn base_command_data_mut(&mut self) -> &mut BaseCommandData; - fn composer(&self) -> Option { + fn composer(&self) -> Option { self.base_command_data().composer.clone() } - fn composer_mut(&mut self) -> &mut Option { + fn composer_mut(&mut self) -> &mut Option { &mut self.base_command_data_mut().composer } @@ -292,7 +292,7 @@ impl BaseCommand for C { required: bool, disable_plugins: Option, disable_scripts: Option, - ) -> Result> { + ) -> Result> { if required { return Ok(Some( self.require_composer(disable_plugins, disable_scripts)?, @@ -306,7 +306,7 @@ impl BaseCommand for C { &mut self, _disable_plugins: Option, _disable_scripts: Option, - ) -> Result { + ) -> Result { // TODO(phase-b): depends on Application::get_composer, which is still stubbed. let _ = RuntimeException { message: String::new(), @@ -319,12 +319,12 @@ impl BaseCommand for C { &mut self, _disable_plugins: Option, _disable_scripts: Option, - ) -> Option { + ) -> Option { // TODO(phase-b): depends on Application::get_composer, which is still stubbed. todo!("try_composer pending Application::get_composer") } - fn set_composer(&mut self, composer: PartialComposerHandle) { + fn set_composer(&mut self, composer: AnyComposerHandle) { *self.composer_mut() = Some(composer); } @@ -388,7 +388,7 @@ impl BaseCommand for C { ); // TODO(phase-b): event_dispatcher.dispatch expects Option; need wrapper from // PreCommandRunEvent. - let _ = composer.borrow_partial().get_event_dispatcher(); + let _ = composer.get_event_dispatcher(); let _ = pre_command_run_event.get_name(); } @@ -481,7 +481,7 @@ impl BaseCommand for C { config: Option>, disable_plugins: bool, disable_scripts: Option, - ) -> Result { + ) -> Result { let disable_plugins = disable_plugins || input.has_parameter_option(&["--no-plugins"], false); let disable_scripts = disable_scripts.unwrap_or(false) -- cgit v1.3.1