From 42b5f9e321c918cef542c120ad21ba8a7339eb29 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 25 Jul 2026 12:16:25 +0900 Subject: refactor(operation): replace OperationInterface with AnyOperation enum Operations are only ever constructed by the dependency resolver, so a plugin has no way to inject an implementation of its own and the set is closed. Modelling it as an enum, like AnyPackage, removes the OperationInterface trait together with its two parallel downcast mechanisms (as_any() + downcast_ref, and as_*_operation()) and the get_package() default method that panicked on UpdateOperation. The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() : getPackage()`, written out at six call sites, becomes AnyOperation::get_target_package(). InstallationManager's three blocks that matched on the type string and then recovered the type with expect() collapse into exhaustive matches. SolverOperation keeps only its TYPE constant; the shared getOperationType()/__toString() implementations move to AnyOperation, which also drops the five Self::TYPE.to_string() allocations. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/create_project_command.rs | 2 +- crates/shirabe/src/command/reinstall_command.rs | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/create_project_command.rs b/crates/shirabe/src/command/create_project_command.rs index 8ea4f07f..fdc01391 100644 --- a/crates/shirabe/src/command/create_project_command.rs +++ b/crates/shirabe/src/command/create_project_command.rs @@ -1002,7 +1002,7 @@ impl CreateProjectCommand { let mut installed_repo = InstalledArrayRepository::new()?; im.execute( &mut installed_repo, - vec![std::rc::Rc::new(InstallOperation::new(package.clone()))], + vec![InstallOperation::new(package.clone()).into()], true, true, false, diff --git a/crates/shirabe/src/command/reinstall_command.rs b/crates/shirabe/src/command/reinstall_command.rs index c2c3ab18..bf10aeed 100644 --- a/crates/shirabe/src/command/reinstall_command.rs +++ b/crates/shirabe/src/command/reinstall_command.rs @@ -6,8 +6,7 @@ use crate::command::base_command::base_command_initialize; use crate::console::input::InputArgument; use crate::console::input::InputOption; use crate::dependency_resolver::Transaction; -use crate::dependency_resolver::operation::InstallOperation; -use crate::dependency_resolver::operation::OperationInterface; +use crate::dependency_resolver::operation::AnyOperation; use crate::dependency_resolver::operation::UninstallOperation; use crate::io::IOInterfaceImmutable; use crate::package::base_package; @@ -175,7 +174,7 @@ impl Command for ReinstallCommand { let mut install_order = indexmap::IndexMap::new(); for (index, op) in install_operations.iter().enumerate() { - if let Some(install_op) = op.as_any().downcast_ref::() + if let AnyOperation::Install(install_op) = op && install_op.get_package().as_alias().is_none() { install_order.insert(install_op.get_package().get_name(), index); @@ -241,10 +240,8 @@ impl Command for ReinstallCommand { indexmap::IndexMap::new(), ); - let uninstall_operations: Vec> = uninstall_operations - .into_iter() - .map(|op| std::rc::Rc::new(op) as std::rc::Rc) - .collect(); + let uninstall_operations: Vec = + uninstall_operations.into_iter().map(Into::into).collect(); { let mut local_repo_ref = local_repo.borrow_mut(); let repo = local_repo_ref -- cgit v1.3.1